A simple example of dns query functionality implemented by Python

  • 2020-06-01 10:20:00
  • OfStack

This article illustrates the simple dns query functionality implemented by Python as an example. I will share it with you for your reference as follows:


#!/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)

For more information about Python, please check out the topics on this site: summary of Python Socket programming skills, summary of Python functions, summary of Python string manipulation skills, introduction and advanced classic course of Python and summary of Python files and directories.

I hope this article has been helpful to you in Python programming.


Related articles: