Operating System - Microsoft
1748128 Members
3651 Online
108758 Solutions
New Discussion юеВ

Re: get IP address using VB script

 
SOLVED
Go to solution
'chris'
Super Advisor

get IP address using VB script

hi

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 ?
5 REPLIES 5
Marc Carney
Valued Contributor
Solution

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
Jon Finley
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

Next

Next

objOutputFile.WriteLine(strReportLine)
objOutputFile.Close

Set objFileSystem = Nothing

Jon
"Do or do not. There is no try!" - Yoda
Ken wanderer
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
Gene Laoyan
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
Next
Next



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

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

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
next

myinfo = myip & vbCRLF & myhost & vbCRLF & mytime

wscript.echo "This is your Public Foreward Facing IP Address: " & vbcrlf & myinfo
End Sub
Chad Miller_5
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

Value

<%= name %>

<%= Request.ServerVariables(name) %>