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

yipeiwu_com6年前Python基础

本文实例讲述了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)

更多关于Python相关内容感兴趣的读者可查看本站专题:《Python Socket编程技巧总结》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总

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

相关文章

python通过定义一个类实例作为ftp回调方法

本文实例讲述了python通过定义一个类实例作为ftp回调方法。分享给大家供大家参考。具体实现方法如下: class Writer: def __init__(self, fil...

Django中多种重定向方法使用详解

前言 本文使用了Django1.8.2 使用场景,例如在表单一中提交数据后,需要返回到另一个指定的页面即可使用重定向方法 一、 使用HttpResponseRedirect fu...

PyTorch使用cpu加载模型运算方式

没gpu没cuda支持的时候加载模型到cpu上计算 将 model = torch.load(path, map_location=lambda storage, loc: stor...

Linux下用Python脚本监控目录变化代码分享

#!/usr/bin/env python #coding=utf-8 import os from pyinotify import WatchManager, Notifier...

Python进阶_关于命名空间与作用域(详解)

写在前面 如非特别说明,下文均基于Python3 命名空间与作用于跟名字的绑定相关性很大,可以结合另一篇介绍Python名字、对象及其绑定的文章。 1. 命名空间 1.1 什么是命名空间...