Operating System - Microsoft
Showing results for 
Search instead for 
Did you mean: 

get IP address using VB script

Go to solution
Super Advisor

get IP address using VB script


howto get IP address of the WIN2000 workstation using VB script ?

I have this VB script:

Set WshNetwork = WScript.CreateObject("WScript.Network")
WScript.Echo "You Computer Name = " & WshNetwork.ComputerName

to get the Computer Name, but howto add the line to get the IP address ?
Valued Contributor

Re: get IP address using VB script

I don't use VB so cannot help you there, but can you in some way incorporate the command:

ipconfig/all|find/I"IP ADDRESS"

and take only the part you require.

The IP address is also hidden away in the registry, but looks like it comes under a sub key which is based on a GUID type string.

You may also get problems with computers with several net adapters.

Sorry can't be more help.
The sheep tell me what I need to know
Honored Contributor

Re: get IP address using VB script

IP Address is an array. Here's an example that might help.

'---- get ip addresses and mac address of available NIC's
strComputer = "."
Set SWBemlocator = CreateObject("WbemScripting.SWbemLocator")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set cItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration",,48)
For Each objItem in cItems

For Each propValue in objItem.IPAddress
MyIP = objItem.IPAddress(0)
MyMac= objItem.MACAddress(0)
strReportLine = strReportLine & " IPMAC:"&MyIP&","&MyMac&","

' objOutputFile.WriteLine(MyIP&","&MyMac&",")
' Console.WriteLine(MyIP&","&MyMac)
' Wscript.WriteLine(MyIP&","&MyMac)
' WScript.Echo "IPAddress: " & MyIP & "MACaddress " &MyMac




Set objFileSystem = Nothing

"Do or do not. There is no try!" - Yoda
Trusted Contributor

Re: get IP address using VB script

On the Domain Server,
Go to my computer and right click on it.
Then go to Manage.
Then go to DNS
Then go to forward lookup zone
Then the systems and IP are listed on the right.
Otherwise my AV program lists them.
You are using DHCP ?
Work Smarter Not Harder
Super Advisor

Re: get IP address using VB script

Get your internal LAN IP Address...
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration")

For Each objItem In colItems
For Each objValue In objItem.IPAddress
If objValue <> "" Then
WScript.Echo "Description -- " & objItem.Description & vbcrlf & "IPAddress -- " & objValue & vbcrlf & "MAC: " & objItem.MACAddress
End If

Get your External Public IP...
Call EnumPublicIP()

Sub EnumPublicIP()
const URL = "http://xml.showmyip.com/"
set xmldoc = CreateObject("Microsoft.XMLDOM")

for each x in xmldoc.documentElement.childNodes
if x.NodeName = "ip" then
myip = x.text
end if
if x.NodeName = "host" then
myhost = x.text
end if
if x.NodeName = "timestamp" then
mytime = x.text
end if

myinfo = myip & vbCRLF & myhost & vbCRLF & mytime

wscript.echo "This is your Public Foreward Facing IP Address: " & vbcrlf & myinfo
End Sub
Trusted Contributor

Re: get IP address using VB script

In VBS for web pages, the command is request.servervariables("remote_host"). This variable holds the address of the remotely connected browser.

Use the following array to iterate through all the server variables and their values:

<% For Each name In Request.ServerVariables %>

<% Next %>

Server Varriable


<%= name %>

<%= Request.ServerVariables(name) %>