Detect If IPv6 is Enabled on Windows Machines

蹲街弑〆低调 提交于 2019-12-04 15:42:35

You can use the .NET way :

Write-Host 'OS Supports IPv6: ' $( [System.Net.Sockets.Socket]::OSSupportsIPv6 )

The property will be true if it is possible to create an IPv6 datagram socket. This property is also affected by the global machine.config file, so the IPv6 status may not always be accurate.

Edit: To test this on a remote machine, you can still use powershell, but it has to have powershell 2.0 installed, and WinRM enabled.

If those two conditions are true, then you can probably use Invoke-Command to do that.

Testing for IPv6 would usually be more complicated than a yes/no answer with XP you have,

  1. Is the "Microsoft TCP/IP version 6" network component installed.
  2. Is there an adapter has an IPv6 address - one would usually assume (1) implies (2).
  3. Whether an adapter has a global-scope IPv6, i.e. not just a link local fe80:: prefixed address or loopback interface, ::1.

Presumaly (1) can be found with a Powershell script as demonstrated by Microsoft:

http://gallery.technet.microsoft.com/ScriptCenter/en-us/c4eb1596-7ac9-4be7-a711-b43446a3e3df

Actually, a colleague came up with a nice way of doing it - a little clunky but works. :)

$IPV6 = $false
$arrInterfaces = (Get-WmiObject -class Win32_NetworkAdapterConfiguration -filter "ipenabled = TRUE").IPAddress

foreach ($i in $arrInterfaces) {$IPV6 = $IPV6 -or $i.contains(":")}

write-host $IPV6

If you want to specifically check that IPv6 is enabled and working, I'd say the best way would be to try and connect to a test host. That way, you won't just test some specific software setting, but you'll also find out so that all the routing configuration and everything around it works as it should.

This is what you didn't want to do, but it seems the best method, going over the output that netsh interface provides.

You may want to look here for what you're after. Your implementation would be simpler, but iterating over the netsh interface ipv6 show interfaces results is all you need, if you find interfaces, it's enabled somewhere, if you don't find any, it's not.

I've not tested this, but the .NET Socket class has a OSSupportsIPv6 property. So something along the lines

[System.Net.Sockets]::OSSupportsIPv6

The documentation says "true if the operating system and network adaptors support the IPv6 protocol; otherwise, false." It isn't clear to me if that means the value is based on what the OS is capable of, or what it is configured for.

I looked this up in my local help, so I don't have a MSDN link handy. Shouldn't be too hard to find.

I know this is an old thread but I needed to check the same thing.

To check ipv6 binding for a specific adapter use:

 Get-NetAdapterBinding -Name 'NameOfNic' -ComponentID ms_tcpip6

This will give you the enabled state for that adapter.

If you want to just retrieve that state you can use:

 (Get-NetAdapterBinding -Name 'NameOfNic' -ComponentID ms_tcpip6).Enabled

Hope this helps. I did check that this works as far back as 2012. docs.microsoft.com didn't list versions below default for 2012/Win8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!