Skip to content

Instantly share code, notes, and snippets.

@deybhayden
Created October 20, 2023 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deybhayden/f0a22a776e649dcafb22d65fcab64fda to your computer and use it in GitHub Desktop.
Save deybhayden/f0a22a776e649dcafb22d65fcab64fda to your computer and use it in GitHub Desktop.
Get current outbound IP in Python
import re
from urllib.request import urlopen
def get_ip():
d = str(urlopen("http://checkip.dyndns.com/").read())
re_srch = re.compile(r"Address: (\d+\.\d+\.\d+\.\d+)").search(d)
if re_srch:
return re_srch.group(1)
print(f"Current IP: {get_ip()}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment