# -*- coding: cp936 -*-
"""域名解析程序"""
import sys,socket
"""
输入参数:
host, port [, family, socktype, proto, flags]
host:www.baidu.com
port:80
family:AF_INET
socktype:socket.STREAM
proto:default 0
flags:
输出参数为tuple的列表,即一个域名可以对应多个ip
family:AF_INET,AF_UNIX...
socktype:STREAM,DGRAM
proto:0
canonname:
sockaddr:xxx.xxx.xxx.xxx
"""
host = "www.baidu.com"
print socket.getaddrinfo(host,None)
print socket.getaddrinfo(host,"http")
print socket.getaddrinfo(host,"http",socket.AF_INET)
print socket.getaddrinfo(host,"http",socket.AF_INET,socket.SOCK_STREAM)
"""
输出结果
[(2, 0, 0, '', ('202.108.22.5', 0)), (2, 0, 0, '', ('202.108.22.43', 0))]
[(2, 1, 0, '', ('202.108.22.5', 80)), (2, 1, 0, '', ('202.108.22.43', 80))]
[(2, 1, 0, '', ('202.108.22.5', 80)), (2, 1, 0, '', ('202.108.22.43', 80))]
[(2, 1, 0, '', ('202.108.22.5', 80)), (2, 1, 0, '', ('202.108.22.43', 80))]
"""
|