例子,python socket模块打印dns查询。
代码:
#!/usr/bin/python
#site: www.jb200.com
#
import socket
def gethost_ex(host_ex):
hostname_ex,alias_ex,address_ex = socket.gethostbyname_ex(host_ex)
return hostname_ex,alias_ex,address_ex
def array_print(*arr):
for item in arr:
print ' ',item
print
for host in ["www.baidu.com","www.jb200.com","www.google.com"]:
print host
try :
hostname,alias,address = gethost_ex(host)
except socket.error as e:
print 'error',e
continue
print ' HostName:',hostname
print ' Alias:'
array_print(*alias)
print ' Address:'
array_print(*address)