strComputer = "." Set objWMIService = GetObject(_ "winmgmts:\\" & strComputer & "\root\cimv2") Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapter " _ & "Where NetConnectionID = " & _ "'Local Area Connection 2'")
For Each objItem in colItems strMACAddress = objItem.MACAddress Next
Set colItems = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
If objItem.MACAddress = strMACAddress Then
For Each strIPAddress in objItem.IPAddress
Wscript.Echo "IP Address: " & strIPAddress
Next
End If
Next
VB
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNics = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapter " _
& "Where NetConnectionID = " & _
"'Local Area Connection'")
For Each objNic in colNics
Set colNicConfigs = objWMIService.ExecQuery _
("ASSOCIATORS OF " _
& "{Win32_NetworkAdapter.DeviceID='" & _
objNic.DeviceID & "'}" & _
" WHERE AssocClass=Win32_NetworkAdapterSetting")
For Each objNicConfig In colNicConfigs
For Each strIPAddress in objNicConfig.IPAddress
Wscript.Echo "IP Address: " & strIPAddress
Next
Next
Next
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration ")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) _
to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next
PowerShell
$Computer = "."
$IPconfigset = Get-WmiObject Win32_NetworkAdapterConfiguration
# Iterate and get IP address
$count = 0
foreach ($IPConfig in $IPConfigSet) {
if ($Ipconfig.IPaddress) {
foreach ($addr in $Ipconfig.Ipaddress) {
"IP Address : {0}" -f $addr;
$count++
}
}
}
if ($count -eq 0) {"No IP addresses found"}
else {"$Count IP addresses found on this system"}
strComputer = "."
Set objWMIService = GetObject(_
"winmgmts:\\" & strComputer & "\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration " _
& "where IPEnabled=TRUE")
For Each objNetAdapter In colNetAdapters
errEnable = objNetAdapter.EnableDHCP()
Next
strComputer = "."
Set objWMIService = GetObject( _
"winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfiguration" _
& " where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) _
to UBound(IPConfig.IPAddress)
WScript.Echo IPConfig.IPAddress(i)
Next
End If
Next
strComputer = "." Set objWMIService = GetObject(_ "winmgmts:\\" & strComputer & "\root\cimv2") Set colPings = objWMIService.ExecQuery _ ("Select * From Win32_PingStatus where Address = '192.168.1.1'")
For Each objStatus in colPings
If IsNull(objStatus.StatusCode) _
or objStatus.StatusCode<>0 Then
WScript.Echo "Computer did not respond."
Else
Wscript.Echo "Computer responded."
End If
Next
VB
strComputer = "client1"
Set objShell = CreateObject("WScript.Shell")
Set objScriptExec = objShell.Exec( _
"ping -n 2 -w 1000 " & strComputer)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
If InStr(strPingResults, "destination net unreachable") Then
WScript.Echo strComputer & "did not respond to ping."
Else
WScript.Echo strComputer & " responded to ping."
End If
Else
WScript.Echo strComputer & " did not respond to ping."
End If