-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpygeoseeker.py
141 lines (123 loc) · 5.08 KB
/
pygeoseeker.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
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
import os
import platform
import subprocess
import sys
import time
import ipinfo
from termcolor import cprint
from argparse import ArgumentParser
class PyGeoSeeker:
def __init__(self):
self.os_name = platform.system()
self.main()
@staticmethod
def banner():
from pyfiglet import Figlet
f = Figlet(font='slant')
print('\n')
cprint(f.renderText('P y G e o'), 'yellow')
cprint(f.renderText('S e e k e r'), 'yellow')
print('\n')
@staticmethod
def is_package_installed(package_name):
try:
import importlib
importlib.import_module(package_name)
return True
except ImportError:
return False
def install_missing_packages(self, packages):
checkmark = '\u2713'
try:
if self.os_name == 'Windows':
missing_packages = [pkg for pkg in packages if not self.is_package_installed(pkg)]
if missing_packages:
print(f"Installing missing packages: {', '.join(missing_packages)}")
subprocess.check_call([sys.executable, '-m', 'pip', 'install', *missing_packages])
print(f'\nInstallation finished. [{checkmark}]')
time.sleep(2)
os.system('cls')
else:
print(f'\nRequirements already installed. [{checkmark}]')
time.sleep(2)
os.system('cls')
elif self.os_name == 'Linux':
missing_packages = [pkg for pkg in packages if not self.is_package_installed(pkg)]
if missing_packages:
print(f"Installing missing packages: {', '.join(missing_packages)}")
subprocess.check_call([sys.executable, '-m', 'pip', 'install', *missing_packages])
print(f'\nInstallation finished. [{checkmark}]')
time.sleep(2)
os.system('clear')
else:
print(f'\nRequirements already installed. [{checkmark}]')
time.sleep(2)
os.system('clear')
else:
missing_packages = [pkg for pkg in packages if not self.is_package_installed(pkg)]
if missing_packages:
print(f"\nInstalling missing packages: {', '.join(missing_packages)}")
subprocess.check_call([sys.executable, '-m', 'pip', 'install', *missing_packages])
print(f'\nInstallation finished. [{checkmark}]')
time.sleep(2)
os.system('cls')
else:
print(f'\nRequirements already installed. [{checkmark}]')
time.sleep(2)
sys.stdout.flush()
except Exception as ex:
print('\nAn exception occurred: \n', ex)
def main(self):
parser = ArgumentParser(description='--------Geolocation tracker--------',
usage='python pygeoseeker.py --help',
epilog='python3 pygeoseeker.py '
'--target [IP] '
'--access-token [TOKEN]')
parser.add_argument_group('Required Arguments:')
parser.add_argument(
"-t", "--target",
type=str,
metavar="<target>",
help="Target IP to track location",
required=True
)
parser.add_argument(
"-token", "--access-token",
type=str,
metavar="<token>",
help="IPinfo access token, to obtain one, sign up at https://ipinfo.io",
required=True
)
args = parser.parse_args()
self.pygeoseeker(args.target, args.access_token)
@staticmethod
def pygeoseeker(target_ip, ipinfo_token):
try:
connection = ipinfo.getHandler(ipinfo_token)
get_details = connection.getDetails(target_ip)
cprint(f"Geolocation Details for {target_ip}:", 'green', attrs=['bold'])
cprint("--------------------------------------------------", 'green', attrs=['bold'])
cprint("Key | Value", 'green', attrs=['bold'])
cprint("--------------------------------------------------", 'green', attrs=['bold'])
for key, value in get_details.all.items():
cprint(f"{key:<20} | {value}", 'yellow')
cprint("--------------------------------------------------", 'green', attrs=['bold'])
print('\n')
except KeyboardInterrupt:
print('\n')
cprint(f"PyGeoSeeker Terminated.", 'green')
print('\n')
except Exception as e:
cprint(f"Error: {e}", 'red')
if __name__ == '__main__':
# You can run, but you can't hide
required_packages = [
'ipinfo',
'termcolor',
'colorama',
'pyfiglet'
]
PyGeoSeeker.banner()
PyGeoSeeker().install_missing_packages(required_packages)
PyGeoSeeker.banner()
PyGeoSeeker()