python管理dns

使用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

发表评论

电子邮件地址不会被公开。 必填项已用*标注