Converting static IP's to DHCP

Easiest way I've found to do this is to scan the subnet scope with nmap, and output the results to a text file. You can then put the text file into excel and use formula's to create a formated list. That list format can then be put into DHCP with reservations using a vbscript.

nmap is available at http://nmap.org/download.html

nmap -sP 192.168.1.0/24 > somefile.txt

Should give you a result like:

MAC Address: 00:14:38:D2:F5:3F (Hewlett Packard)
Nmap scan report for 192.168.1.1
Host is up (-0.12s latency).
MAC Address: 00:E0:81:56:AF:9E (Tyan Computer)
Nmap scan report for 192.168.1.2
Host is up (-0.12s latency).
MAC Address: 00:C0:02:A1:BC:5F (Sercomm)
Nmap scan report for 192.168.1.3
Host is up (-0.12s latency).
MAC Address: 00:26:55:14:31:47 (Hewlett Packard)
Nmap scan report for 192.168.1.4
Host is up (0.00046s latency).

Use excel to import and format the data so it shows as:

192.168.1.1,001438DCF53F
192.168.1.2,00E08156AF9E
192.168.1.3,00C002A1BC5F
192.168.1.4,002655143147

Save the file into a text document, named ListFile.txt.

You can then use the vbscript below to add the reservations to your DHCP server. The script must be run on a windows DHCP server.


Set fso = Wscript.CreateObject("Scripting.FileSystemObject")

Set shell = Wscript.CreateObject("Wscript.Shell")

Set ipList=fso.OpenTextFile("c:\ListFile.txt", 1, false)

Do While not ipList.AtEndOfStream
rLine=Trim(ipList.readLine)
MAC = Right(rLine, Len(rLine) - InStrRev(rLine, ","))
IP = Left(rLine, InStrRev(rLine, ",") - 1)
If not IP = "" or MAC = "" then
shell.run "netsh dhcp server scope xxx.xxx.xxx.yyy add reservedip " & IP & " " & MAC, 0, True

End If
Loop

You should of course double check any previous static IP documentation available, as nmap can easily miss devices configured to not respond.