Last active
June 7, 2021 14:05
-
-
Save czaux/b729a5de8d1334afbbe147a6bcee55e1 to your computer and use it in GitHub Desktop.
Get External IP with whoami.cloudflare and DNSPython
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
import dns.resolver #dnspython | |
my_resolver = dns.resolver.Resolver() | |
#Cloudflares DNS Server | |
my_resolver.nameservers = ['1.1.1.1'] | |
#Get IP from cloudflare chaosnet TXT record | |
#https://community.cloudflare.com/t/can-1-1-1-1-be-used-to-find-out-ones-public-ip-address/14971/6 | |
result = my_resolver.resolve("whoami.cloudflare","TXT", "CH", tcp=True, lifetime=15) | |
response = result.response | |
answer = response.answer | |
ExternalIP = str(list(answer[0])[0]).replace('"', '') | |
print(ExternalIP) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment