Python DNS服务器IP地址查询 [英] Python DNS Server IP Address Query

查看:280
本文介绍了Python DNS服务器IP地址查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用python获取DNS服务器IP地址.要在Windows命令提示符下执行此操作,我将使用

I am trying to get the DNS Server IP Addresses using python. To do this in Windows command prompt, I would use

ipconfig -all

ipconfig -all

如下所示:

我想使用python脚本做完全相同的事情.有什么方法可以提取这些值? 我成功提取了设备的IP地址,但是事实证明DNS服务器IP更具挑战性.

I want to do the exact same thing using a python script. Is there any way to extract these values? I was successful in extracting the IP address of my device, but DNS Server IP is proving to be more challenging.

推荐答案

DNS Python( dnspython )可能会有所帮助.您可以通过以下方式获取DNS服务器地址:

DNS Python (dnspython) might be helpful. You can get the DNS server address with:

 import dns.resolver
 dns_resolver = dns.resolver.Resolver()
 dns_resolver.nameservers[0]

这篇关于Python DNS服务器IP地址查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆