Click here to Skip to main content
13,094,732 members (96,208 online)
Click here to Skip to main content
Add your own
alternative version


29 bookmarked
Posted 26 Jun 2014

Network Utility

, 26 Jun 2014
Rate this:
Please Sign up or sign in to vote.
A Network Utility application to get system information and analyze your network


Network Utility is a trivial application to get system information and analyze your network. It's trivial because some of its features can be performed using the Windows command line tool. The purpose of this article is to provide some information on how some of the features were implemented and the .net namespaces and classes used.

The utility has four separate features, each of which is detailed below.

  • System Information
  • Net Stat
  • Ping
  • Port Scanner

System Information

Information about your system, such as the machine name or username can be found in either System.Environment or System.Windows.Forms.SystemInformation. These namespaces provide system related information with very little coding. If you want to get network information such as a MAC address, use the System.Net.NetworkInformation. This namespace has a handy class called NetworkInterface that has a static GetAllNetworkInterfaces() method which returns a collection of NetworkInterface's. By iterating over this collection, you can examine and get details for each interface. The Network Utility application makes use of both these namespaces to display system and network information.

Net Stat

Net Stat displays active TCP connections. It is a simple version of the netstat command line tool, which provides more details about active connections. To my surprise, I found that the System.Net.NetworkInformation has a IPGlobalProperties class with a static GetIPGlobalProperties() method, which returns a IPGlobalProperties object. Using this object, I was able to get a list of all active TCP connections using the GetActiveTcpConnections() method. The code below shows how to get a list of active TC connections and display the remote address and port.

IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();

foreach (TcpConnectionInformation info in connections)

The Address property is an instance of IPAddress. Using this instance, you can attempt to resolve its hostname by using the Dns class, which is found in the System.Net namespace. The Dns class has a static GetHostEntry() method, which will attempt to resolve the IP address to a hostname. It should be noted, that if you have many connections, doing a DNS lookup on each IP may take some time. Resolving to a hostname has the benefit of identifying the connections.

The Window's netstat command line tool has a useful argument (netstat -o), which displays the system process id (PID) used by a connection. With a PID, you can easily determine the application and take any action if needed. I was hoping the .Net framework would have a class that can return the PID's for connections. Unfortunately, it doesn't. However there is an unmanned IP Helper API (GetExtendedTcpTable function) that can be be used to get the PID for each connection. More information about this function can be found here.


The purpose of a ping is to determine the reachability of a host and the time it takes to respond. It works by sending an Internet Control Message Protocol packet to a target machine and measures the time it takes from initial sending to receiving a response and records any packet loss. It turns out, the .Net framework provides a Ping class found in the System.Net.NetworkInformation namespace, which makes pinging very simple. The Ping class reference on the MSDN website provides a simple example usage.

Port Scanner

Scanning for open ports, seems like something a hacker might want to do, but it is also useful for network administrators, who want to monitor which ports are open on their systems. While the .Net framework doesn't provide a port scanning class, it is actually very simple to code. Using the TcpClient class found in the System.Net.Sockets namespace and attempting to connect to a given host using a particular port will suggest if the port is open. If a connection is made, it suggests there is an application listening on that port.

	TcpClient client = new TcpClient("", "80");
	// Port open
catch (Exception e){
	// port closed.

This brings me to the end of this article. Please feel free to leave your comments and suggestions.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Syed M Hussain
Web Developer
United Kingdom United Kingdom
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionLink is dead Pin
Member 107799667-Apr-17 9:14
memberMember 107799667-Apr-17 9:14 
QuestionReally bad website. Pin
YDLU20-Jan-17 0:55
memberYDLU20-Jan-17 0:55 
QuestionFilter Pin
R3COV3RY11-Sep-14 2:29
memberR3COV3RY11-Sep-14 2:29 
GeneralPort scanner Pin
Riz Thon29-Jun-14 15:35
memberRiz Thon29-Jun-14 15:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170813.1 | Last Updated 26 Jun 2014
Article Copyright 2014 by Syed M Hussain
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid