开发者

How to detect if a windows machine is running IPV4 or IPV6?

Is there 开发者_Python百科anyway to determine if a windows computer is running IPV6 using native utilities, python or php?


This is how I solved the issue, by trying to open up an IPv6 socket. If the system did not throw an error, then it is using IPv6.

import socket

def isIPV6():   
    ipv6 = True
    try:
        s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
    except:
        ipv6 = False
    return ipv6


Sure. If ipconfig contains an IPv6 Address entry for a real interface, you've probably got IPv6 connectivity. There are also useful registry entries at HKLM\SYSTEM\CurrentControlSet\services\TCPIP6.


Every computer ships with IPv4 at standard. IPv6 is only enabled on specific machines. But if you parse ifconfig/ipconfig then you should find yourself a IPv4/6 address in the output


Enumerate the interfaces and check for an IPv6 address, like everyone else has stated. Alternatives include trying to open an IPv6 socket or get Python to call WSCEnumProtocols()


Jakob's approach is the simplest; you could pipe the result and do a match to see whether a network adapter has a valid IPv6 address.

Additionally, you could get this by fetching the Windows Management Instrumentation class Win32_NetworkAdapterConfiguration. The property IPAddress is an array of all the IP addresses associated with a network adapter and you can match against them to see if there is a IPv6 address associated. But PS is a bit of an overkill, I'd go with Jakob's or Wyatt's answer unless you'd need to do something more intelligible and fancy (send an HTTP request; change some network rules; restart a service).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜