Click here to Skip to main content
13,049,814 members (72,503 online)
Rate this:
Please Sign up or sign in to 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 16-Apr-13 20:20pm
Manfred R. 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.

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Refer this Link it will help

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


Siva Rm K
Rate this: bad
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)
  { // 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("");        // true (loopback IP)
IsLocalIpAddress("MyNotebook");       // true (my computer name)
IsLocalIpAddress("");      // true (my IP)
IsLocalIpAddress("NonExistingName");  // false (non existing computer name)
IsLocalIpAddress("");         // false (non existing IP in my net)

Marcus Kramer 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2017
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