Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Command line to get my public IP address by leveraging handy feature in OpenDNS
# 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
You can’t perform that action at this time.