-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAnyIPTrack.py
More file actions
203 lines (175 loc) · 11.3 KB
/
AnyIPTrack.py
File metadata and controls
203 lines (175 loc) · 11.3 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
try:
import ctypes
import subprocess, colorama, requests, base64, os, socket
import sys
from colorama import Fore, Style
from pystyle import Center, Colors, Colorate, System, Anime
import time
except ModuleNotFoundError:
print("Exception when importing modules")
print("Installing necessary modules....")
if os.path.isfile("requirements.txt"):
os.system("pip install -r requirements.txt")
else:
os.system("pip install pystyle")
os.system("pip install colorama")
os.system("pip install requests")
print("Modules installed!")
os._exit(1)
"""
color
"""
colorama.init()
anydesk_pids = []
anydesk_address = {}
ip_addr = []
old_port = 0
old_ip = ''
def setTitle(_str):
system = os.name
if system == 'nt':
ctypes.windll.kernel32.SetConsoleTitleW(f"{_str} - Enjoy")
elif system == 'posix':
sys.stdout.write(f"\x1b]0;{_str} - Enjoy\x07")
else:
pass
def clear():
system = os.name
if system == 'nt':
os.system('cls')
elif system == 'posix':
os.system('clear')
return
def center(var: str, space: int = None): # From Pycenter
try:
if not space:
space = (os.get_terminal_size().columns - len(var.splitlines()[int(len(var.splitlines()) / 2)])) / 2
return "\n".join((' ' * int(space)) + var for var in var.splitlines())
except OSError:
print(
f"{Fore.BLUE}\nStart the program from a normal terminal.\n{Fore.WHITE}If you have any problems you can contact me through my discord (https://discord.com/users/925933412710232105)")
time.sleep(1)
os._exit(1)
print(f" ")
print(f" ")
print(f"{Fore.BLUE} █████╗ ███╗ ██╗██╗ ██╗██████╗ ███████╗ ██████╗██╗ ██╗")
print(f" ██╔══██╗████╗ ██║╚██╗ ██╔╝██╔══██╗██╔════╝██╔════╝██║ ██╔╝")
print(f" ███████║██╔██╗██║ ╚████╔╝ ██║ ██║█████╗ ╚█████╗ █████═╝ ")
print(f" ██╔══██║██║╚████║ ╚██╔╝ ██║ ██║██╔══╝ ╚═══██╗██╔═██╗ ")
print(f" ██║ ██║██║ ╚███║ ██║ ██████╔╝███████╗██████╔╝██║ ╚██╗")
print(f" ╚═╝ ╚═╝╚═╝ ╚══╝ ╚═╝ ╚═════╝ ╚══════╝╚═════╝╚═╝ ╚═╝ ")
print(f" ")
print(f" ")
print(f"{Fore.BLUE} ██╗██████╗ ")
print(f" ██║██╔══██╗")
print(f" ██║██████╔╝")
print(f" ██║██╔═══╝ ")
print(f" ██║██║ ")
print(f" ╚═╝╚═╝ ")
print(f"{Fore.LIGHTCYAN_EX} By MikeDevQH")
print(f" ")
print(f"{Fore.BLUE} ████████╗██████╗ █████╗ ██████╗██╗ ██╗")
print(f" ╚══██╔══╝██╔══██╗██╔══██╗██╔════╝██║ ██╔╝")
print(f" ██║ ██████╔╝███████║██║ █████╔╝ ")
print(f" ██║ ██╔══██╗██╔══██║██║ ██╔═██╗ ")
print(f" ██║ ██║ ██║██║ ██║╚██████╗██║ ██╗")
print(f" ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝")
print(f" {Fore.RED}waiting for connection...")
while 1:
try:
if str(subprocess.check_output("tasklist")).count('AnyDesk') <= 3:
pass
else:
for line in str(subprocess.check_output("tasklist")).replace('b"', '"').replace('\\r', '').replace('\\n',
'\n').split(
'\n'):
if 'AnyDesk' in line:
try:
anydesk_pids.append(line.split('.exe')[1].split()[0].replace(' ', ''))
except Exception as e:
pass
nstats_output_lines = str(subprocess.check_output('netstat -p TCP -n -a -o')).replace('b"', '"').replace(
'\\r', '').replace('\\n', '\n').split('\n')
for pid in anydesk_pids:
for line in nstats_output_lines:
if pid in line and not 'LISTENING' in line:
try:
parts = line.split()
protocol = parts[0]
local_addr = parts[1]
remote_addr = parts[2].split(':')[0]
remote_port = parts[2].split(':')[1]
anydesk_address[remote_addr] = int(remote_port)
except Exception as e:
print(e)
for ip, port in anydesk_address.items():
if int(port) > old_port and not '169.254.' in ip:
old_port = int(port)
old_ip = ip
remote_ip = old_ip
remote_port = old_port
print(f'{Fore.GREEN} connection established!')
def ipinfo_command(ip_address):
"""
Get information about an IP address
"""
try:
socket.inet_pton(socket.AF_INET, ip_address) # Check the IP address
r = requests.get(
f'http://ip-api.com/json/{ip_address}?fields=status,message,continent,continentCode,country,countryCode,region,regionName,lat,lon,city,timezone,isp,org,as,asname,reverse,query')
r_json = r.json()
if r_json['status'] == 'success':
continent = r_json['continent']
continentCode = r_json['continentCode']
country = r_json['country']
countryCode = r_json['countryCode']
region = r_json['region']
regionName = r_json['regionName']
city = r_json['city']
timezone = r_json['timezone']
isp = r_json['isp']
org = r_json['org']
as_ = r_json['as']
asname = r_json['asname']
lat = r_json['lat']
lon = r_json['lon']
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f' {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}IP --> {Fore.LIGHTCYAN_EX}{remote_ip:<19}')
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}Continent --> {Fore.LIGHTCYAN_EX}{continent} ({continentCode:})")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}Country --> {Fore.LIGHTCYAN_EX}{country} ({countryCode})")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}Region --> {Fore.LIGHTCYAN_EX}{regionName} ({region:})")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}City --> {Fore.LIGHTCYAN_EX}{city:<19}")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}Timezone --> {Fore.LIGHTCYAN_EX}{timezone:<25}")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}Lat --> {Fore.LIGHTCYAN_EX}{lat}")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}Lon --> {Fore.LIGHTCYAN_EX}{lon}")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}ISP --> {Fore.LIGHTCYAN_EX}{isp:<25}")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}ORG --> {Fore.LIGHTCYAN_EX}{org:<25}")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
print(f" {Fore.LIGHTWHITE_EX}| {Fore.LIGHTBLUE_EX}AS --> {Fore.LIGHTCYAN_EX}{asname} ({Fore.LIGHTBLUE_EX}{as_:<22}{Fore.LIGHTCYAN_EX})")
print(f" {Fore.LIGHTWHITE_EX}+------------------+--------------------------------------+")
else:
print(
f'\n {Fore.BLUE}[{Fore.LIGHTBLUE_EX}ERR{Fore.LIGHTCYAN_EX}OR{Fore.BLUE}] {Fore.LIGHTCYAN_EX}The IP address is not valid.')
except requests.exceptions.ConnectionError:
print(f'\n {Fore.BLUE}[{Fore.LIGHTBLUE_EX}ERR{Fore.LIGHTCYAN_EX}OR{Fore.BLUE}] {Fore.LIGHTCYAN_EX}Could not connect to API.')
except socket.error:
print(f'\n {Fore.BLUE}[{Fore.LIGHTBLUE_EX}ERR{Fore.LIGHTCYAN_EX}OR{Fore.BLUE}] {Fore.LIGHTCYAN_EX}The IP address is not valid.')
try:
ipinfo_command(remote_ip)
except Exception as e:
print(f'{Fore.LIGHTBLUE_EX}aia. {Fore.LIGHTCYAN_EX + e}')
print(f'\n\n {Fore.BLUE}[{Fore.LIGHTBLUE_EX}>{Fore.BLUE}] {Fore.LIGHTWHITE_EX}Closing AnyIP... # Created by {Fore.LIGHTCYAN_EX}MikeDevQH{Fore.RESET}')
input(Fore.GREEN + 'Press \'enter\' to exit...')
exit()
except KeyboardInterrupt:
print(f'\n\n {Fore.RED}[{Fore.LIGHTRED_EX}>{Fore.RED}] {Fore.LIGHTWHITE_EX}Closing AnyIP... # Created by {Fore.LIGHTCYAN_EX}MikeDevQH{Fore.RESET}')
exit()