如何通过批处理文件获取全局IPv6地址

时间:2016-07-19 11:52:49

标签: windows batch-file

我想获取存储在变量中的计算机的全局IPv6地址。

我找到了这段代码,但它只提供了Link-Local地址。

for /f "delims=[] tokens=2" %%a in ('ping %computername% -6 -n 1 ^| findstr "["') do (set ipv6=%%a)

1 个答案:

答案 0 :(得分:1)

在vbscript中我们可以这样做:

获取 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

获取 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