PHP前端开发

分享Python实现dns查询功能实例

百变鹏仔 3小时前 #Python
文章标签 查询功能

这篇文章主要介绍了python实现的简单dns查询功能,结合实例形式分析了python基于socket模块的dns信息查询实现技巧,需要的朋友可以参考下

本文实例讲述了Python实现的简单dns查询功能。分享给大家供大家参考,具体如下:

#!/usr/bin/pythonimport sys,socketdef print_array(*arr):    array = arr    for item in array:        print item[4][0]print '''this script is for host resolveprint "now this begin...if you want to leave,please input "break"'''while 1:    try:        host = raw_input("please input the host: ")    except KeyboardInterrupt:        print "",        continue    except :        print "",        continue    if host == "break" or host == "":        break    result = socket.getaddrinfo(host,None,0,socket.SOCK_STREAM)    print_array(*result)