When using VBScript in a network environment you sometimes want to retrieve the IP
to use it, for example, to retrieve the correct server from which you want to
This isn't an easy task. The IP address isn't set in the environment when the computer
boots, so we've got to use another method to retrieve the address.
The method which I use in the script below is reading the IP address from the
in the registry. This makes sure that, even when you use DHCP, you get the right IP address.
The script contains two functions:
GetIPAddress you get an array
which contains the IP address. Remember that element 0 in the array is actually the first octet of
your IP address.
wscript.echo GetIPOctet (1)
Above you find a little example which prints out the first octet of the IP address.
Here you find the complete script as it is now. Include it in your own programs at your own risk.
Always be careful, since you are reading the registry.
Set oSh = CreateObject("WScript.Shell")
cIPAddressKey=cInterfaceskey + cNicServiceName+"\IPAddress"
Function GetIPOctet (nOctet)