Created
October 20, 2023 15:37
-
-
Save deybhayden/f0a22a776e649dcafb22d65fcab64fda to your computer and use it in GitHub Desktop.
Get current outbound IP in Python
This file contains hidden or 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 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