Python端口检查器 - 无法访问的网络

时间:2013-03-26 15:30:53

标签: python port connect ipv6

我需要帮助。
两周前,像这样的代码没有问题,并测试了 IPv6地址的端口,但现在突然抛出异常
代码:

print "IPv4 connection..."
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
    s.connect(('173.194.70.101', 80))
    s.shutdown(2)
    print "Success connection"
except socket.error as e:
    sys.stderr.write("Error: " + str(e))
    print "Cannot connect"


print "IPv6 connection..."
s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
try:
    s.connect(('2a00:1450:4001:c02:0:0:0:8b', 80))
    s.shutdown(2)
    print "Success connection"
except socket.error as e:
    sys.stderr.write("Error: " + str(e))
    print "Cannot connect"


控制台:

IPv4 connection...
Success connection
IPv6 connection...
Cannot connect
Error: [Errno 10051] A socket operation was attempted to an unreachable network

1 个答案:

答案 0 :(得分:2)

你的例子适合我。

问题是您没有可用的IPv6连接。