-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequests_tools.py
More file actions
33 lines (31 loc) · 1.2 KB
/
requests_tools.py
File metadata and controls
33 lines (31 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
def get_ip_info(ip):
try:
response = requests.get(f"http://ip-api.com/json/{ip}?fields=status,message,country,regionName,city,zip,lat,lon,isp,org,as")
data = response.json()
if data.get("status") == "success":
info = (
f"Country: {data.get('country')}\n"
f"Region: {data.get('regionName')}\n"
f"City: {data.get('city')}\n"
f"ZIP: {data.get('zip')}\n"
f"Latitude: {data.get('lat')}\n"
f"Longitude: {data.get('lon')}\n"
f"ISP: {data.get('isp')}\n"
f"Org: {data.get('org')}\n"
f"AS: {data.get('as')}\n"
)
return info
else:
return f"Error: {data.get('message')}"
except Exception as e:
return f"Request Error: {e}"
def get_http_headers(url):
if not url.startswith("http"):
url = "http://" + url
try:
response = requests.head(url, timeout=5)
headers = "\n".join(f"{k}: {v}" for k, v in response.headers.items())
return headers
except Exception as e:
return f"Error fetching headers: {e}"