3

I am getting all system name connected in LAN network. I don't know how to get IP Address of all system name like (192.168.1.15).

3

2 Answers 2

6

This might do the trick for you

foreach(NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
    foreach (UnicastIPAddressInformation ip in ni.GetIPProperties().UnicastAddresses)
    {
        if(!ip.IsDnsEligible)
        {
            if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
            {
                // All IP Address in the LAN
            }
        }
    }
}

The Only drawback of this code is that the information returned by instances of UnicastIPAddressInformation is not available for operating systems earlier than Windows XP.

1
  • Thnq..in comment all ip address in lan how can i get that in richtextbox..Kindly help! Nov 24, 2015 at 10:23
1

If you already know the hostnames (as your question implies), you can use the Dns.GetHostAddresses method to translate them to IP addresses.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.