-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·100 lines (86 loc) · 2.56 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/python3
# -*- coding: UTf-8 -*-
from random import choice
import sys, os
import requests
import rich.console
import rich.traceback
from ua import user_agents
import json
console = rich.console.Console(
width=os.get_terminal_size().columns, height=os.get_terminal_size().lines
)
def get_data(hosts: list | tuple) -> ("host", requests.Response):
h2_params = "?fields=status,country,countryCode,isp,proxy,query"
old_h = ""
for h in hosts:
if debug:
console.print(f"Getting data from {h}", justify="center")
try:
if h == hosts[1]:
old_h = h
h += h2_params
response = requests.get(h, headers=choice(user_agents))
if debug:
console.print(f"HTTP [{response.status_code}]", justify="center")
if response.ok:
if old_h == hosts[1]:
h = old_h
return h, response
else:
if debug:
console.print(response.text)
continue
except:
continue
else:
console.print("[red]Failed to get any data! Check connection.", justify="center")
sys.exit(1)
hosts = [
"http://ip-api.com/json/",
"https://ipapi.co/json",
"https://api.myip.com",
]
if __name__ == "__main__":
debug = True if "--debug" in sys.argv else False
h, response = get_data(hosts)
data = response.text
data = json.loads(data)
t = "IPv4"
isp = ""
proxy = ""
country = ""
wt = "[white]"
gn = "[green]"
gr = "[gray]"
if debug:
console.print(data)
console.print(f"Host: {h}")
if h == hosts[1]:
t = data["version"]
ip = data["ip"]
h0_cn = data["country_name"]
h0_cc = data["country"]
country = f"{wt}Location: {gn}[b][i]{h0_cn} ({h0_cc})[/i][/b]"
elif h == hosts[0]:
ip = data["query"]
h1_cc = data['countryCode']
h1_cn = data['country']
h1_proxy = data['proxy']
country = f"{wt}Location: {gn}[b][i]{h1_cn} ({h1_cc})[/i][/b]"
isp = f"{wt}ISP: {gn}[b][i]{data['isp']}[/i][/b]"
proxy = f"{gr}Is Proxy, VPN or Tor exit address: {gn}[b][i]{h1_proxy}[/i][/b]"
else:
ip = data["ip"]
h2_cn = data["country"]
h2_cc = data["cc"]
country = f"{wt}Location: {gn}[b][i]{h2_cn} ({h2_cc})[/i][/b]"
console.print(
f"{wt}{t}: {gn}[b][i]{ip}[/i][/b]",
country,
isp,
proxy,
sep="\n",
justify="center",
)
response.close()