Friday, 8 June 2012

Creating a Port Scanner in C#

Creating a Port Scanner in C#/List all occupied ports in a System



     IPGlobalProperties gp=System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();
            Console.WriteLine("Computer Name={0}",gp.HostName);



            Console.WriteLine("TCP Active Listeners");
            foreach (IPEndPoint ipe in gp.GetActiveTcpListeners())
            {
                Console.WriteLine(ipe.Address+"\t\t"+ipe.AddressFamily+"\t\t"+ipe.Port);
            }
OUTPUT
List Active Tcp Active Connections  using C#
            IPGlobalProperties gp=System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties();
            Console.WriteLine("Computer Name={0}",gp.HostName);
            Console.WriteLine("TCP Active TCP Connections");
            foreach(TcpConnectionInformation tci in gp.GetActiveTcpConnections())
            {
                Console.WriteLine(tci.LocalEndPoint.Address + "\t\t" + tci.LocalEndPoint.AddressFamily + "\t\t" + tci.LocalEndPoint.Port);
            }

OUTPUT