Skip to content

Ip address

loke meng lee

Asked Jul 23, 2008, 4:09 AM EDT1 answer
Share
LinkedInX
say i was only given port numbers of all running servers in a particular LAN network.
Any hint on how to obtained the corresponding ip addresses for these ports?

Thanks in advance

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • Bechir Bejaoui
    0
    using System.Net;
    private static void GetAllIPAdresses(string[] Servers)
    {
        try
        {
            string[] ServerNames = Servers;
           
            int index = 0;
            System.Net.IPHostEntry[] oEntry;
            IPAddress[] ipAdresses;
            for (index = 0; index < ServerNames.Length; index++)
            {
                oEntry[index] = Dns.GetHostByName(ServerNames[index]);
                IPAddress[] ipAdresses = oEntry[index].AddressList;
                foreach (IPAddress ip in ipAdresses)
                {
                    Console.WriteLine(ip.Address.ToString());
                }
            }
            Console.Read();
        }
        catch (System.Net.Sockets.SocketException caught) { Console.WriteLine(caught.Message);Console.Read();}
    }

    I 'm not sure that it work but It certainly saves some efforts
    0