Who Is On My Network

A Software How-To In C#

 
Ever felt a bit paranoid and wondered just what or who is connected to your network??? I do, that's why I decided to do a little fun programming and came up with Communication Manager.
 
It's a  little program to find all valid IPs being used and identify what they are. I was surprised when I first ran it. I had no idea it would pick up so many things. Good news is, all connections were valid.
 
Who Is On My Network
 
The program is made very simple utilizing the System.NET library, specifically Sockets, DNS, and Network Information. The program starts by obtaining the hostname and associated IPs from System.Net.Dns (Domain Naming Service) and determines whether the IPs are v6 or v4.
 
Some other fun stuff - all the active ports are obtained using System.IO.Ports.SerialPort.GetPortNames(), network interfaces are processed (see below), and even though it has little to do with communication/networking; the active drives are listed out using System.IO.DriveInfo.GetDrives().
 
The real fun comes from processing the active IPs on the network. This is where you can find out if anyone has hacked into your network. The program uses the base IP address, the first three sets of numbers from the IP (i.e. 000.000.000.xxx where xxx equals 0 thru 255), and runs a loop for all the possible IPs except for the host's IP. Each IP is pinged for status reply: positive reply denotes active IP. System.Net.NetworkInformation.Ping() is utilized for this purpose.
 
All active IPs are captured and queried for the connection information which is held within the valid reply. The other piece of information you need is obtained by using System.Net.Dns.GetHostEntry(IP address).HostName. It really comes down to just processing information.
 
For example, to process all the network interfaces.
  1. NetworkInterface[] niNetInterface = NetworkInterface.GetAllNetworkInterfaces();  
Now, you just go through the retrieved list and process the information for each network interface. Information such as Description, Interface Type, Physical Address, Bytes received and sent, etc…
 
Other items of interest - if someone is learning C#, the application is WPF, a timer is created and utilized, formatting for drive sizes, updating control data sources. This is a Visual Studio 2010 version project but you will have no trouble porting it to a more recent version of Visual Studio if you need to. It is straightforward and commented. The project source code can be found here: ComMgr
 
Enjoy!
 
End Of Line, Man!


Similar Articles