Skip to content

Commit

Permalink
Better IP
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmogul committed Sep 24, 2023
1 parent 00205f0 commit 2d0a4b9
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,22 @@
import socket


def getUrl(timeout=5) -> str:
def get_url(timeout=5) -> str:
try:
response = requests.get("https://ident.me", timeout=timeout)
response = requests.get("https://api.ipify.org?format=json", timeout=timeout)
response.raise_for_status() # Raises a HTTPError if the response was unsuccessful
result = response.text

# Parse the JSON response
ip_data = response.json()
result = ip_data["ip"]
except requests.exceptions.RequestException as x:
print(type(x), x)
result = "0.0.0.0"
try:
response = requests.get("https://ident.me", timeout=timeout)
response.raise_for_status() # Raises a HTTPError if the response was unsuccessful
result = response.text
except requests.exceptions.RequestException as x:
print(type(x), x)
result = "0.0.0.0"
return result


Expand Down

0 comments on commit 2d0a4b9

Please sign in to comment.