DNS域名系统

由ip查域名:

(family, type, proto, canonname, sockaddr)=socket.getaddrinfo(host, port, family=0, type=0, proto=0, flags=0)

#-*- coding='gb2312' -*-
import socket
if __name__ == '__main__':
    result=socket.getaddrinfo("www.baidu.com",None)
    for item in result:
         print(item[4])
('115.239.211.110', 0)
('115.239.210.27', 0)

由域名查ip:

            (hostname, aliaslist, ipaddrlist)=socket.gethostbyaddr(ip_address)

#-*- coding='gb2312' -*-
import socket
if __name__ == '__main__':
    try:
        result=socket.gethostbyaddr("127.0.0.1")
        print(result[0])    
    except socket.herror:
        print("error")
activate.adobe.com
posted @ 2014-06-08 16:03  sxcww  阅读(188)  评论(0编辑  收藏  举报