detect ip conflict using C#

Is there any way to detect the message IP conflict? I will be using this in a thread in my program.

13.10.2009 19:03:44
I honestly have no idea what you are asking for. Can you describe the problem in a more detailed way?
John Gietzen 13.10.2009 19:06:30
Sounds like he wants to handle the system event for when your IP address conflicts with another user on the same segment. If there is an Event it is probably tucked away in WMI land.
Matthew Whited 13.10.2009 19:16:44
2 ОТВЕТА

If your problem is locating the alert window saying there is a duplicate IP on the network, I suggest your use the API to enumerate all windows and see if the alert window is there. You may be helped by Visual Studio tool Spy++ to see the characteritics of the window.

2
13.10.2009 19:12:42

The question is not particular precise and old but I'll give it a go anyways because I wondered what I can do about such problems since I'm writing an app that manipulates IP addresses on the PC in order to launch applications which are dependent on specific addresses. If anyone else has the same question I suggest trying to avoid any conflicts in the first place. The thing is that setting an IP address is an administrative task and should only be done "free-handed" by people who know what they are doing. If you are setting IP addresses via code is is your task as a developer to check if the address to set is valid and not already known on the network.

First: Query DNS if this address belongs to a host other than the one the app runs on

Second: If DNS doesn't know about the address, send Ping requests to the address.

See: Check Local Ip Address

    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;
}

If you want to "listen" for conflicts, the WMI and EventLog is the way to go. The EventLog is pretty much the first place where such conflicts surface and it is easy to monitor.

0
28.11.2017 14:21:00
RFC 5227, IPv4 Address Conflict Detection, among others, covers this.
Ron Maupin 28.11.2017 15:05:32