python socket模块实现dns查询的例子

发布时间:2020-02-26编辑:脚本学堂
分享一个使用python中socket模块实现dns查询的小例子,学习下python模块socket的用法,有需要的朋友参考下。

python socket,python模块,dns查询

例子,python socket模块实现dns查询。

代码:
 

复制代码 代码示例:

#!/usr/bin/python
#site: www.jb200.com
#
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)