python进行dns查询的一段代码

发布时间:2021-01-19编辑:脚本学堂
python进行dns查询的一段代码,有需要的朋友可以参考下。

python进行dns查询的一段代码,有需要的朋友可以参考下。
 

复制代码 代码如下:

#!/usr/bin/python
import sys,socket

def print_array(*arr):
        array = arr
        for item in array:
                print item[4][0]

print '''this script is for host resolve
print "now this begin...
if you want to leave,please input "break"'''

while 1:
        try:
                host = raw_input("please input the host: ")
        except KeyboardInterrupt:
                print "n",
                continue
        except :
                print "n",
                continue

        if host == "break" or host == "":
                break
        result = socket.getaddrinfo(host,None,0,socket.SOCK_STREAM)
        print_array(*result)