如何检测 Windows 机器是运行 IPV4 还是 IPV6?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4268865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to detect if a windows machine is running IPV4 or IPV6?
提问by CLJ
Is there anyway to determine if a windows computer is running IPV6 using native utilities, python or php?
无论如何,是否可以使用本机实用程序、python 或 php 来确定 Windows 计算机是否正在运行 IPV6?
回答by CLJ
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.
这就是我通过尝试打开 IPv6 套接字来解决该问题的方法。如果系统没有抛出错误,那么它正在使用 IPv6。
import socket
def isIPV6():
ipv6 = True
try:
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
except:
ipv6 = False
return ipv6
回答by Wyatt Anderson
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
.
当然。如果ipconfig
包含IPv6 Address
真实接口的条目,则您可能已获得 IPv6 连接。也有有用的注册表项HKLM\SYSTEM\CurrentControlSet\services\TCPIP6
。
回答by Jakob Bowyer
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
每台计算机都标配 IPv4。IPv6 仅在特定机器上启用。但是如果你解析 ifconfig/ipconfig 那么你应该在输出中找到一个 IPv4/6 地址
回答by Steve-o
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()
枚举接口并检查 IPv6 地址,就像其他人所说的那样。替代方法包括尝试打开 IPv6 套接字或让 Python 调用WSCEnumProtocols()
回答by Filip Dupanovi?
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.
Jakob 的方法是最简单的;您可以通过管道传输结果并进行匹配以查看网络适配器是否具有有效的 IPv6 地址。
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).
此外,您可以通过获取 Windows Management Instrumentation 类Win32_NetworkAdapterConfiguration来获得它。该属性IPAddress
是与网络适配器关联的所有 IP 地址的数组,您可以与它们进行匹配以查看是否存在IPv6
关联的地址。但是 PS 有点矫枉过正,我会选择 Jakob 或 Wyatt 的回答,除非您需要做一些更容易理解和更花哨的事情(发送 HTTP 请求;更改一些网络规则;重新启动服务)。