Next step of programming

Just another WordPress.com weblog

Posts Tagged ‘IPGLOBALPROPERTIES

Netstat in C#

without comments

Check out how to perform Netstat command functions of DOS in C#. It will list you all the current network connections of your System


using System;
using System.Net;
using System.Net.NetworkInformation;

namespace MyNetstat
{
class Program    
{
static void Main(string[] args)
{
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();

IPEndPoint[] endPoints = ipProperties.GetActiveTcpListeners();
TcpConnectionInformation[] tcpConnections = ipProperties.GetActiveTcpConnections();

foreach (TcpConnectionInformation info in tcpConnections)
{
Console.WriteLine("Local : " + info.LocalEndPoint.Address.ToString()
+ ":" + info.LocalEndPoint.Port.ToString()
+ "\nRemote : " + info.RemoteEndPoint.Address.ToString()
+ ":" + info.RemoteEndPoint.Port.ToString()
+ "\nState : " + info.State.ToString() + "\n\n");
}
Console.ReadLine();
}
}
}

Written by A.Sethi

February 9, 2009 at 12:09 pm

Getting TCP/IP Statistic through C#

without comments

Getting the TCP/IP Statistic is very easy through C#. Since all the required methods and properties are there in framework. To get the TCP/IP Statistic we have to use the following nampespace

using System.Net.NetworkInformation;

Now to get the statistic we have to IPGlobalProperties class and extract the information out of it to our TCP/IP statistic object

IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpStatistics tcpstat = null;

now with following line you will get all the details for IPv4

tcpstat = properties.GetTcpIPv4Statistics(); 

and to get the details of IPv6 you use following line

tcpstat = properties.GetTcpIPv6Statistics(); 

now we can get details from this object. Details like data sent, recieved, total connections and various other

Written by A.Sethi

September 23, 2008 at 7:39 am