Click here to Skip to main content
15,884,913 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
My app has a feature to allow users to set the IP address of the system on which it is running. Is there any way for my application to detect if the IP address entered by the users is already taken by any other device on the network before I update the NIC settings ? I intend to display my own custom message box if this IP conflict occurs and I dont want to update the NIC card settings if an IP conflict has occured.

I can think of 2 approaches for this issue:

1. Do a network ping for the entered IP address and wait for a response. But would this method fail to detect an IP address conflict if a system has been disabled to respond to pings ?

2. Get a list of all IP addresses in the current network and check if the entered IP address already exists. In .Net , how do I determine the list of all IP addresses in the network ?

Please see that I am looking for a programmatic approach to solving the issue.
Posted
Comments
Manfred Rudolf Bihy 17-Apr-13 3:02am    
I'm a very curious person so I would like to ask you if you could explain the scenario your application is used in a bit closer. I can't for the life of me not figure out why I should give a "normal" user the power to change the IP adress of the system. It's so counter intuitive as all communication (TCP/IP and UDP wise) relies on correct IP adresses and there is usually infrastructure that makes sure the systems get the correct IP adress (DHCP etc.).

Please do explain what you are up to, as I'm almost bursting with anticipation.

Cheers!

Hi
Refer this Link it will help


Retreiving a list of network computer names using C# - Click Here

Thanks

Siva Rm K
 
Share this answer
 
Try this:



C#
IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());
string localComputerName = Dns.GetHostName();
public static bool IsLocalIpAddress(string host)
{
  try
  { // get host IP addresses
    IPAddress[] hostIPs = Dns.GetHostAddresses(host);
    // get local IP addresses
    IPAddress[] localIPs = Dns.GetHostAddresses(Dns.GetHostName());

    // test if any host IP equals to any local IP or to localhost
    foreach (IPAddress hostIP in hostIPs)
    {
      // is localhost
      if (IPAddress.IsLoopback(hostIP)) return true;
      // is local address
      foreach (IPAddress localIP in localIPs)
      {
        if (hostIP.Equals(localIP)) return true;
      }
    }
  }
  catch { }
  return false;
}


IsLocalIpAddress("localhost");        // true (loopback name)
IsLocalIpAddress("127.0.0.1");        // true (loopback IP)
IsLocalIpAddress("MyNotebook");       // true (my computer name)
IsLocalIpAddress("192.168.0.1");      // true (my IP)
IsLocalIpAddress("NonExistingName");  // false (non existing computer name)
IsLocalIpAddress("99.0.0.1");         // false (non existing IP in my net)
 
Share this answer
 
Comments
fjdiewornncalwe 17-Apr-13 13:55pm    
Plagiarized from Source

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900