如何通过batch file获取全球IPv6地址

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

我发现这个代码,但它只给出链接本地地址。

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

在VBScript中,我们可以做这样的事情:

获得仅IPv6Address.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