-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintmap
42 lines (34 loc) · 1.28 KB
/
intmap
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
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import requests
import argparse
def get_ip_info(ip_address):
url = f"http://ip-api.com/json/{ip_address}"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
return data
else:
return None
def print_ip_info(ip_info):
if ip_info and ip_info.get('status') == 'fail':
print(f"Error: {ip_info.get('message')}")
elif ip_info:
print(f"IP Address: {ip_info.get('query')}")
print(f"City: {ip_info.get('city')}")
print(f"Region: {ip_info.get('regionName')}")
print(f"Country: {ip_info.get('country')}")
print(f"Location: {ip_info.get('lat')}, {ip_info.get('lon')}")
print(f"ISP: {ip_info.get('isp')}")
# Create Google Maps URL
maps_url = f"https://www.google.com/maps?q={ip_info.get('lat')},{ip_info.get('lon')}"
print(f"Google Maps URL: {maps_url}")
else:
print("IP information could not be retrieved.")
def main():
parser = argparse.ArgumentParser(prog="intmap", description="intmap [options]")
parser.add_argument('ip_address', type=str, help="The IP address to query.")
args = parser.parse_args()
ip_info = get_ip_info(args.ip_address)
print_ip_info(ip_info)
if __name__ == "__main__":
main()