Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to use a netsh script to change the IP address on a box that's headless. This works fine, unless there's an IP conflict. When an IP address conflict occurs, I see a dialog box that says "The static IP address that was just configured is already in use on the network. Please reconfigure a different IP address." In this case, netsh just hangs waiting for someone to acknowledge the dialog box.

I won't be the one using the script, and the users who are will definitely cause an IP conflict sometimes. Is there a way to get netsh to just return an error code instead? Anything would be better than just hanging.

share|improve this question

I suspect the dialog is not being displayed by netsh, but rather by the operating system when it detects an IP address conflict.

You could try and ping the desired IP address, and if no response is obtained, assume the address is free and set it using netsh. The following vbscript provides an example:

Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.Exec("ping -n 2 -w 2000")

sResult = LCase(oExec.StdOut.ReadAll)
If InStr(sResult, "reply from") Then
  WScript.Echo "IP address is in use"
  oShell.Run "netsh interface ip set address name=" _
  & Chr(34) & "Local Area Connection" _
  & Chr(34) & " static 1", 1, 1
End If

The script sends 2 ping packets, 2 seconds apart, and checks for a response that includes "reply from". You could even configure the script to increment the IP address and try again until an unused address is found.

You could also try a something similar using nslookup, as ping will only work if the computer with the conflicting IP is currently turned on.

share|improve this answer
Ping isn't reliable enough for me. Plenty of devices can refuse pings while still using the IP. – TimK Nov 14 '09 at 13:45
In fact the correct way is to do a ARP request. – David Costa May 6 '11 at 10:16
up vote 0 down vote accepted

The best way I found to do this was to wait for a certain amount of time, and then kill the netsh process if it hadn't completed. I did this by spawning a separate process for netsh from C#.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.