首頁  >  文章  >  後端開發  >  分享Python實作dns查詢功能實例

分享Python實作dns查詢功能實例

零下一度
零下一度原創
2017-05-26 17:43:171866瀏覽

這篇文章主要介紹了Python實現的簡單dns查詢功能,結合實例形式分析了Python基於socket模組的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)

【相關推薦】

1. 分享Python實現SMTP發送郵件圖文實例

# 2. 利用Python實現Youku視訊批次下載功能實例

3. 分享python中and / or 的運算邏輯實例教學

#4. Python:邏輯判斷與運算子實例

以上是分享Python實作dns查詢功能實例的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn