Investigate your network with NetPing
- Posted: Apr 22, 2007 at 7:10 PM
- 1,794 Views
- 1 Comment
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
| NetPing is an extensible utility that allows for custom display of networked Windows computers, as well as the ability to perform custom actions on these computers. | |
|
Difficulty: Intermediate
Time Required:
Less than 1 hour
Cost: Free
Hardware:
Download: Download
|
|
Many households, and most businesses, have more than one computer. Being able to remotely monitor and maintain these computers can save valuable minutes every day. NetPing makes these tasks a little easier by serving two purposes: Simple display of computer information and the ability to perform actions on these computers. What makes the application truly useful, though, is the ability to easily add to the application's functionality with add-ins written in .NET. Add-ins come in two flavors: ColoumnProviders, which display information for each computer in a single column, and ContextMenuItemProviders that allow the user to execute an action via context menu.
When NetPing is launched, it loads all add-ins in the AddIns directory. When the Start button is pressed, all IP addresses in the given range are pinged and ColumnProvider add-ins are executed for each that respond. Finally, ContextMenuItemProvider add-ins are executed when the user right-clicks a row and selects an item from the context menu.
In the screen shot below, ‘Name', ‘Uptime' and ‘Operating System' are ColumnProvider add-ins. ‘Remote Deskop' and ‘System Information' are ContextMenuItemProviders.
NetPing consists of the following projects:
· NetPing: This contains the core application. MainForm and HostListViewItem are where the most of the action lives, but most of this action involves threading and is outside the scope of this article. The classes are fully commented, so the adventurous are welcome to dig around.
· NetPing.Common: Common contains what could be considered the NetPing ‘SDK' (software development kit). It contains the classes that add-in authors use to integrate with NetPing.
· NetPing.AddIns: Finally, AddIns contains the ‘Name', ‘Uptime', ‘Operating System', ‘Remote Desktop' and ‘System Information' add-ins. Note that any number of add-in assemblies may be put into the AddIns directory – this project need not be modified to extend NetPing.
The IColumnProvider interface, shown below, must be implemented by all ColumnProvider add-ins:
The abstract ColumnProviderBase class is provided to make ColumnProvider creation a little easier. Classes that inherit ColumnProviderBase are only required to implement Execute, which returns a ColumnValue object.
The ColumnValue class represents three different values:
Text: This is the text that will be displayed.
SortKey: SortKey is a string that will be used when comparing values during a sort, since the text value of a field doesn't necessarily represent its value. For example, the Uptime column displays uptime in English but its SortKey is a numeric representation of the boot date and time, which sorts chronologically.
ColumnIndex: Indicates which column the row should update with the value.
The simplest ColumnProvider, ComputerNameColumn, is shown below in both Visual Basic and C#.
First, the VB version:
Friend Class ComputerNameColumn Inherits ColumnProviderBase Public Sub New() MyBase.New("Name", 125) End Sub Public Overrides Function Execute(ByVal ipAddress As IPAddress) As ColumnValue Dim hostEntry As IPHostEntry Try hostEntry = Dns.GetHostEntry(ipAddress) Catch hostEntry = Nothing End Try Dim hostName As String If hostEntry Is Nothing Then hostName = "" Else hostName = hostEntry.HostName End If Return New ColumnValue(ColumnIndex, hostName) End Function End Class
And the C# version:
class ComputerNameColumn : ColumnProviderBase { public ComputerNameColumn() : base("Name", 125) {} public override ColumnValue Execute(IPAddress ipAddress) { IPHostEntry hostEntry; try { hostEntry = Dns.GetHostEntry(ipAddress); } catch { hostEntry = null; } string hostName; if (hostEntry == null) { hostName = ""; } else { hostName = hostEntry.HostName; } return new ColumnValue(ColumnIndex, hostName); } }
Writing ContextMenuItemProviders is even easier. The IContextMenuItemProvider interface is shown below, again in C# and Visual Basic:
Text is what is shown on the context menu and Execute is called when the user selects the menu item.
The SystemInformationMenuItem is shown below in C#:
class SystemInformationMenuItem : IContextMenuItemProvider { public void Execute(IPAddress ipAddress) { try { Process.Start("cmd.exe", "/k systeminfo /s " + ipAddress); } catch (Exception e) { MessageBox.Show("An error occurred while retrieving system information:\n\n" + e.Message,
"System information", MessageBoxButtons.OK, MessageBoxIcon.Error); } } public string Text { get { return "System Information"; } } }
And in Visual Basic:
Friend Class SystemInformationMenuItem Implements IContextMenuItemProvider Public Sub Execute(ByVal ipAddress As IPAddress) Implements IContextMenuItemProvider.Execute Try Process.Start("cmd.exe", "/k systeminfo /s " & ipAddress.ToString()) Catch e As Exception MessageBox.Show("An error occurred while retrieving system information:" & _
Constants.vbLf + Constants.vbLf + e.Message, "System information", _
MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Public ReadOnly Property Text() As String Implements IContextMenuItemProvider.Text Get Return "System Information" End Get End Property End Class
All kinds of information is available via WMI (Windows Management Instrumentation). Add-ins can be written to display a computer's CPU, RAM, disk drive information and so on. The OperatingSystemColumn and UptimeColumn classes use WMI to retrieve their values and are a good place to start.
Regarding ContextMenuItemProviders, anything that requires an IP address can be executed. For example, a reboot command could be initiated, ports scanned, Computer Management opened, etc. The options are endless!
Vista's User Account Control may get between NetPing and Vista computers' WMI, and behavior is different for workspace and domain compters. The following articles explain the issue and solutions:
· Connecting to WMI Remotely Starting with Vista
· User Account Control and WMI
Jeff is the Technical Product Manager at InRule Technology and a Visual C# MVP. More stuff like this is available at his website.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
VERY nice. Thanks! I was looking around for multithreading examples so that I could create a similar network health watcher, and received that functionality as well!
Remove this comment
Remove this thread
close