-
Notifications
You must be signed in to change notification settings - Fork 2
/
get_website_info.py
50 lines (46 loc) · 1.42 KB
/
get_website_info.py
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
43
44
45
46
47
48
49
50
"""
sockets=1.0.0
"""
import sys
import json
import socket
from typing import List
from urllib.request import urlopen, Request
def get_website_info(sites: List[str]) -> dict:
"""
Obtain site info by site name
"""
GEO_IP_API_URL = 'http://ip-api.com/json/'
try:
result: dict = {}
for site in sites:
ip = socket.gethostbyname(site)
req = Request(GEO_IP_API_URL+ip)
response = urlopen(req).read()
json_response = json.loads(response.decode('utf-8'))
result_response = {
'ip': ip,
'city': json_response['city'],
'region': json_response['regionName'],
'country': json_response['country']
}
print(f"site: {site}")
print(f"ip: {ip}")
print(f"city: {result_response['city']}")
print(f"region: {result_response['region']}")
print(f"country: {result_response['country']}")
print(f"---------------------------------------")
result[site] = result_response
return result
except Exception as e:
print('error:', e)
print("\nExiting...")
sys.exit(0)
if __name__ == "__main__":
sites: List[str] = [
'www.facebook.com',
'www.instagram.com',
'www.google.com',
'www.netflix.com',
]
(get_website_info(sites))