Think before you speak, read before you think.

python管理dns

by

in

使用dnspython模块

pip install dnspython

查询A记录

import dns.resolver
ip = dns.resolver.query("jpuyy.com", "A")
for i in ip:
    print i

写个函数查询多条记录

#!/usr/bin/env python
#-*- coding:utf-8 -*-

import dns.resolver

hosts = ["jpuyy.com", "hupu.com", "hao123.com", "ifeng.com"]

def query(host_list = hosts):
    collection = []
    for host in host_list:
        ip  =  dns.resolver.query(host,"A")
        for i in ip:
            collection.append(str(i))
    return collection

if __name__ == "__main__":
    for arec in query():
        print arec

来自python for unix and linux system Administration


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *