Checking IP conflict using Powershell

Hi, I have to write a powershell script for checking if there is an address conflict.

We have several laptops, but only two can be connected at the same time, one with ip .24 and the other with .25, we cannot have dhcp server.

My idea is to launch a powershell script at startup or logon, the script should check if there is another pc with the same address, if there is another computer with the same ip it should change its address to the other, so the .24 should become .25 and viceversa.

How can I check ip conflict in powershell?

 

Thanks, Pietro.

Why not just hardcode the IP address?

Is a bit long to explain, but I have to automatically manage the situation in which two laptops with the same ip could be present on the same network.

 

Thanks, Pietro.

Since the system requires an IP address at least to check if someone else has same IP, there is only one way I could see here,

set the ip address and get it, if it is not returning APIPA range, then no conflict has occurred.

[quote quote=166253]Since the system requires an IP address at least to check if someone else has same IP, there is only one way I could see here,

[/quote]

I can give .24 or .25 static ip to the pc, but I need to check using powershell if there is an ip conflict. Windows emits an alert when it finds a ip conflict, I supposed I could intercept this alert using powershell.

I’m trying something similar, I’m giving to the pc an ip in a range (not a dhcp, but simply I choose a random ip out of a pool of five or six), then I check if .24 or .25 are in use and then I choose the one that is free. It is not what I want, but I’ve to start somewhere.

 

Thanks, Pietro.