脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python实现的简单dns查询功能示例

Python实现的简单dns查询功能示例

2020-11-11 00:45那片依然海 Python

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/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)

希望本文所述对大家Python程序设计有所帮助。

延伸 · 阅读

精彩推荐