本帖最后由 uatlaosiji 于 2017-3-7 17:33 编辑
开始python网络之旅
可能写的不好,编辑的不好,希望能帮助一些人
环境: python 2.7 x86_64 bit debian
检查python是否支持ipv6
[Python] 纯文本查看 复制代码 import socket
socket.has_ipv6
ipv6 建立socket连接:
[Asm] 纯文本查看 复制代码 import socket
socket.has_ipv6
socket.create_connection(address[, timeout[, source_address]])
支持python 2.6版本以上。
版本以下使用
[Asm] 纯文本查看 复制代码 msg = "getaddrinfo returns an empty list"
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
af, socktype, proto, canonname, sa = res
sock = None
try:
sock = socket(af, socktype, proto)
if timeout is not None:
sock.settimeout(timeout)
sock.connect(sa)
return sock
except error, msg:
if sock is not None:
sock.close()
raise error, msg
目前 已验证支持 IPV6的module - socket
- ftplib
- httplib
- imaplib (bug 1655 was fixed in r72662)
- nntplib (bug 1664 was fixed in r72640)
- poplib
- smtplib (but see Python bug 3461)
- telnetlib
- urlparse
- xmlrpclib
|