Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python DNS Server IP Address Query

Tags:

python

bash

cmd

dns

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

ipconfig -all

As shown below:

enter image description here

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.

like image 650
Abhishek Avatar asked Oct 20 '25 12:10

Abhishek


1 Answers

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]
like image 81
Kevin Moore Avatar answered Oct 23 '25 02:10

Kevin Moore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!