Reputation: 1859
How can I find the IP Address of my computer using VBScript?
Upvotes: 1
Views: 27361
Reputation: 9961
This is how you can display the IP address in VB script:
Function getIPAddress()
'Get your Public IP
dim NIC, Nic, StrIPAdd, ComputerName, ipMessage
Set NIC = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Nic in NIC
if Nic.IPEnabled then
StrIPAdd = Nic.IPAddress(0)
Set WshNetwork = WScript.CreateObject("WScript.Network")
ComputerName= WshNetwork.Computername
ipMessage="IP Address: "&StrIPAdd & vbNewLine &"Computer Name: " &ComputerName & vbNewLine &"Date:" ¤tDate
End if
Next
getIPAddress=ipMessage
End Function
Call you function:
ipMessage =getIPAddress()
WScript.Echo ipMessage.
Upvotes: 0
Reputation: 61
This example shows the ip configured and the computer name:
dim NIC1, Nic, StrIP, CompName
Set NIC1 = GetObject("winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
For Each Nic in NIC1
if Nic.IPEnabled then
StrIP = Nic.IPAddress(0)
Set WshNetwork = WScript.CreateObject("WScript.Network")
CompName= WshNetwork.Computername
MsgBox "IP Address: "&StrIP & vbNewLine _
& "Computer Name: "&CompName,4160,"IP Address and Computer Name"
wscript.quit
End if
Next
Upvotes: 6