Created
February 2, 2020 16:43
-
-
Save codingoutloud/e389ca49201b5320776a698d3c7f620e to your computer and use it in GitHub Desktop.
Command line to get my public IP address by leveraging handy feature in OpenDNS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# OpenDNS resolves "myip.opendns.com" to the caller's publicly-facing IP. | |
# To use this feature, resolve that DNS name against an OpenDNS name server. | |
# https://github.com/rthalley/dnspython | |
# pip install dnspython | |
import dns.resolver | |
resolver = dns.resolver.Resolver() | |
opendns_ns_ip = resolver.query('resolver1.opendns.com') | |
resolver.nameservers = [str(opendns_ns_ip[0])] | |
my_ip = resolver.query('myip.opendns.com') | |
print(my_ip[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment