Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows
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 16-Apr-13 21:20pm
Comments
Manfred R. Bihy at 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!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi
 
Refer this Link it will help
 

Retreiving a list of network computer names using C# - Click Here
 
Thanks
 
Siva Rm K
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try this:
 

 
 
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)

 

  Permalink  
Comments
Marcus Kramer at 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)

  Print Answers RSS
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,327
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,920


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100