Reputation: 205
I want to get the Global IPv6 address of a computer stored inside a variable.
I found this code, but it only gives the Link-Local address.
for /f "delims=[] tokens=2" %%a in ('ping %computername% -6 -n 1 ^| findstr "["') do (set ipv6=%%a)
Upvotes: 1
Views: 582
Reputation: 18827
In vbscript we can do something like this :
To get OnlyIPv6Address.vbs
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled = 'True'")
For Each objIP in colSettings
For i=LBound(objIP.IPAddress) to UBound(objIP.IPAddress)
If InStr(objIP.IPAddress(i),":") <> 0 Then msgbox objIP.IPAddress(i)
Next
Next
And to get OnlyIPv4Address.vbs
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration where IPEnabled = 'True'")
For Each objIP in colSettings
For i=LBound(objIP.IPAddress) to UBound(objIP.IPAddress)
If InStr(objIP.IPAddress(i),":") = 0 Then Msgbox objIP.IPAddress(i)
Next
Next
Upvotes: 1