Python网络编程测试-DNS
DNS就是传说中的域名解析,完成域名和IP之间的转换过程,值得注意的是:反向DNS是由IP到域名,这需要和逆向相区别。
Python(2.6以下版本,3.2还没试过,有了解的同学请指教)并没有“原生”的提供DNS相关功能的module,PyDNS(在sourcerage上可以直接搜索到,或者有使用BSD的同学可以使用SVN直接安装)就是一个提供了DNS相关功能的module。
[python] #test of getting infomation of some addr
import sys , socket , time , traceback , DNS
def getAddr(xhost):
try:
host = str(xhost)
except ValueError:
print(e)
try :
res = socket.getaddrinfo(host , None)
except socket.herror , e:
print(e)
print(res[0][4])
def getDNS(servername):
DNS.DiscoverNameServers()
req = DNS.Request()
ans = req.req(name = servername , qtype = DNS.Type.ANY)
print(ans.answers)
#test of getting infomation of some addr
import sys , socket , time , traceback , DNS
def getAddr(xhost):
try:
host = str(xhost)
except ValueError:
print(e)
try :
res = socket.getaddrinfo(host , None)
except socket.herror , e:
print(e)
print(res[0][4])
def getDNS(servername):
DNS.DiscoverNameServers()
req = DNS.Request()
ans = req.req(name = servername , qtype = DNS.Type.ANY)
print(ans.answers)
简单的测试code
摘自 FishinLab的专栏
补充:Web开发 , Python ,