【www.bbyears.com--python】
本文实例讲述了Python实现的简单dns查询功能。分享给大家供大家参考,具体如下:
代码如下
#!/usr/bin/python
importsys,socket
defprint_array(*arr):
array=arr
foriteminarray:
printitem[4][0]
print'''this script is for host resolve
print "now this begin...
if you want to leave,please input "break"'''
while1:
try:
host=raw_input("please input the host: ")
exceptKeyboardInterrupt:
print"\n",
continue
except:
print"\n",
continue
ifhost=="break"orhost=="":
break
result=socket.getaddrinfo(host,None,0,socket.SOCK_STREAM)
print_array(*result)
word-wrap: break-word; margin: 5px 0px; color: rgb(0, 0, 0); font-family: 'sans serif', tahoma, verdana, helvetica; font-size: 13.3333px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 20px; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: 1; word-spacing: 0px; -webkit-text-stroke-width: 0px;">希望本文所述对大家Python程序设计有所帮助。