Skip to content

Instantly share code, notes, and snippets.

@codingoutloud
Created February 2, 2020 16:43
Show Gist options
  • Save codingoutloud/e389ca49201b5320776a698d3c7f620e to your computer and use it in GitHub Desktop.
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
# 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