美文网首页
[python]调用nslookup获取ip

[python]调用nslookup获取ip

作者: 小哥讲笑话 | 来源:发表于2017-11-22 16:40 被阅读530次

    # -*- coding;utf-8 -*-

    import subprocess

    def get_ip(domain):

        res = subprocess.Popen("nslookup {}".format(domain),stdin=subprocess.PIPE,stdout=subprocess.PIPE).communicate()[0]

        response =  res.decode("GBK")

        #print response

        res_list = response.split("s:")

        print"{}:{}".format(domain, res_list[2].split("\r\n")[:-1])

    if __name__ == "__main__":

        get_ip("www.baidu.com")

    相关文章

      网友评论

          本文标题:[python]调用nslookup获取ip

          本文链接:https://www.haomeiwen.com/subject/shkovxtx.html