-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipfinder.py
More file actions
334 lines (288 loc) · 14 KB
/
ipfinder.py
File metadata and controls
334 lines (288 loc) · 14 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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#!/usr/bin/env python3
"""
IPFinder - Passive IP Intelligence and Reconnaissance Tool
Cross-platform, no active scanning, pure OSINT aggregation.
"""
import sys
import socket
import json
import argparse
import time
import threading
from urllib import request, error
import ipaddress
class Colors:
HEADER = '\033[93m' # Yellow for headers
LABEL = '\033[36m' # Cyan for labels
WARNING = '\033[93m' # Yellow for warnings
RESET = '\033[0m'
SEPARATOR = '\033[93m' # Yellow for separators
def disable_colors():
Colors.HEADER = ''
Colors.LABEL = ''
Colors.WARNING = ''
Colors.RESET = ''
Colors.SEPARATOR = ''
class LoadingAnimation:
def __init__(self, message="Fetching data"):
self.message = message
self.is_loading = False
self.thread = None
def __animate(self):
phases = ['. ', '.. ', '...', ' ..', ' .', ' ..', '...', '.. ']
i = 0
while self.is_loading:
sys.stdout.write(f'\r{Colors.HEADER}{self.message}{phases[i % len(phases)]}{Colors.RESET}')
sys.stdout.flush()
i += 1
time.sleep(0.1)
def start(self):
self.is_loading = True
self.thread = threading.Thread(target=self.__animate)
self.thread.daemon = True
self.thread.start()
def stop(self):
self.is_loading = False
if self.thread:
self.thread.join(timeout=0.3)
sys.stdout.write('\r' + ' ' * (len(self.message) + 3) + '\r')
sys.stdout.flush()
def get_public_ip():
endpoints = [
'https://ifconfig.me/ip',
'https://api.ipify.org',
'https://icanhazip.com'
]
for endpoint in endpoints:
try:
with request.urlopen(endpoint, timeout=5) as response:
ip = response.read().decode('utf-8').strip()
if ip and ipaddress.ip_address(ip):
return ip
except:
continue
raise Exception("Could not fetch public IP")
def validate_ip(ip_str):
try:
ipaddress.ip_address(ip_str)
return True
except ValueError:
return False
def ip_to_decimal(ip_str):
return int(ipaddress.ip_address(ip_str))
def reverse_dns_lookup(ip_str):
try:
hostname = socket.gethostbyaddr(ip_str)[0]
return hostname
except (socket.herror, socket.gaierror):
return "N/A"
def fetch_ip_info(ip_str):
try:
url = f"https://ipinfo.io/{ip_str}/json"
with request.urlopen(url, timeout=10) as response:
data = json.loads(response.read().decode('utf-8'))
return data
except error.HTTPError as e:
if e.code == 429:
print(f"{Colors.WARNING}Rate limit exceeded. Try again later.{Colors.RESET}")
return None
except Exception:
return None
def get_country_name(country_code):
country_map = {
'AF': 'Afghanistan', 'AX': 'Åland Islands', 'AL': 'Albania', 'DZ': 'Algeria',
'AS': 'American Samoa', 'AD': 'Andorra', 'AO': 'Angola', 'AI': 'Anguilla',
'AQ': 'Antarctica', 'AG': 'Antigua and Barbuda', 'AR': 'Argentina',
'AM': 'Armenia', 'AW': 'Aruba', 'AU': 'Australia', 'AT': 'Austria',
'AZ': 'Azerbaijan', 'BS': 'Bahamas', 'BH': 'Bahrain', 'BD': 'Bangladesh',
'BB': 'Barbados', 'BY': 'Belarus', 'BE': 'Belgium', 'BZ': 'Belize',
'BJ': 'Benin', 'BM': 'Bermuda', 'BT': 'Bhutan', 'BO': 'Bolivia',
'BQ': 'Bonaire', 'BA': 'Bosnia and Herzegovina', 'BW': 'Botswana',
'BV': 'Bouvet Island', 'BR': 'Brazil', 'IO': 'British Indian Ocean Territory',
'BN': 'Brunei Darussalam', 'BG': 'Bulgaria', 'BF': 'Burkina Faso',
'BI': 'Burundi', 'CV': 'Cabo Verde', 'KH': 'Cambodia', 'CM': 'Cameroon',
'CA': 'Canada', 'KY': 'Cayman Islands', 'CF': 'Central African Republic',
'TD': 'Chad', 'CL': 'Chile', 'CN': 'China', 'CX': 'Christmas Island',
'CC': 'Cocos Islands', 'CO': 'Colombia', 'KM': 'Comoros', 'CG': 'Congo',
'CD': 'Congo (DRC)', 'CK': 'Cook Islands', 'CR': 'Costa Rica',
'CI': "Côte d'Ivoire", 'HR': 'Croatia', 'CU': 'Cuba', 'CW': 'Curaçao',
'CY': 'Cyprus', 'CZ': 'Czech Republic', 'DK': 'Denmark', 'DJ': 'Djibouti',
'DM': 'Dominica', 'DO': 'Dominican Republic', 'EC': 'Ecuador',
'EG': 'Egypt', 'SV': 'El Salvador', 'GQ': 'Equatorial Guinea',
'ER': 'Eritrea', 'EE': 'Estonia', 'SZ': 'Eswatini', 'ET': 'Ethiopia',
'FK': 'Falkland Islands', 'FO': 'Faroe Islands', 'FJ': 'Fiji',
'FI': 'Finland', 'FR': 'France', 'GF': 'French Guiana', 'PF': 'French Polynesia',
'TF': 'French Southern Territories', 'GA': 'Gabon', 'GM': 'Gambia',
'GE': 'Georgia', 'DE': 'Germany', 'GH': 'Ghana', 'GI': 'Gibraltar',
'GR': 'Greece', 'GL': 'Greenland', 'GD': 'Grenada', 'GP': 'Guadeloupe',
'GU': 'Guam', 'GT': 'Guatemala', 'GG': 'Guernsey', 'GN': 'Guinea',
'GW': 'Guinea-Bissau', 'GY': 'Guyana', 'HT': 'Haiti', 'HM': 'Heard Island and McDonald Islands',
'VA': 'Vatican City', 'HN': 'Honduras', 'HK': 'Hong Kong', 'HU': 'Hungary',
'IS': 'Iceland', 'IN': 'India', 'ID': 'Indonesia', 'IR': 'Iran',
'IQ': 'Iraq', 'IE': 'Ireland', 'IM': 'Isle of Man', 'IL': 'Israel',
'IT': 'Italy', 'JM': 'Jamaica', 'JP': 'Japan', 'JE': 'Jersey',
'JO': 'Jordan', 'KZ': 'Kazakhstan', 'KE': 'Kenya', 'KI': 'Kiribati',
'KP': 'North Korea', 'KR': 'South Korea', 'KW': 'Kuwait', 'KG': 'Kyrgyzstan',
'LA': 'Laos', 'LV': 'Latvia', 'LB': 'Lebanon', 'LS': 'Lesotho',
'LR': 'Liberia', 'LY': 'Libya', 'LI': 'Liechtenstein', 'LT': 'Lithuania',
'LU': 'Luxembourg', 'MO': 'Macao', 'MG': 'Madagascar', 'MW': 'Malawi',
'MY': 'Malaysia', 'MV': 'Maldives', 'ML': 'Mali', 'MT': 'Malta',
'MH': 'Marshall Islands', 'MQ': 'Martinique', 'MR': 'Mauritania',
'MU': 'Mauritius', 'YT': 'Mayotte', 'MX': 'Mexico', 'FM': 'Micronesia',
'MD': 'Moldova', 'MC': 'Monaco', 'MN': 'Mongolia', 'ME': 'Montenegro',
'MS': 'Montserrat', 'MA': 'Morocco', 'MZ': 'Mozambique', 'MM': 'Myanmar',
'NA': 'Namibia', 'NR': 'Nauru', 'NP': 'Nepal', 'NL': 'Netherlands',
'NC': 'New Caledonia', 'NZ': 'New Zealand', 'NI': 'Nicaragua',
'NE': 'Niger', 'NG': 'Nigeria', 'NU': 'Niue', 'NF': 'Norfolk Island',
'MK': 'North Macedonia', 'MP': 'Northern Mariana Islands', 'NO': 'Norway',
'OM': 'Oman', 'PK': 'Pakistan', 'PW': 'Palau', 'PS': 'Palestine',
'PA': 'Panama', 'PG': 'Papua New Guinea', 'PY': 'Paraguay', 'PE': 'Peru',
'PH': 'Philippines', 'PN': 'Pitcairn', 'PL': 'Poland', 'PT': 'Portugal',
'PR': 'Puerto Rico', 'QA': 'Qatar', 'RE': 'Réunion', 'RO': 'Romania',
'RU': 'Russia', 'RW': 'Rwanda', 'BL': 'Saint Barthélemy', 'SH': 'Saint Helena',
'KN': 'Saint Kitts and Nevis', 'LC': 'Saint Lucia', 'MF': 'Saint Martin',
'PM': 'Saint Pierre and Miquelon', 'VC': 'Saint Vincent and the Grenadines',
'WS': 'Samoa', 'SM': 'San Marino', 'ST': 'Sao Tome and Principe',
'SA': 'Saudi Arabia', 'SN': 'Senegal', 'RS': 'Serbia', 'SC': 'Seychelles',
'SL': 'Sierra Leone', 'SG': 'Singapore', 'SX': 'Sint Maarten',
'SK': 'Slovakia', 'SI': 'Slovenia', 'SB': 'Solomon Islands',
'SO': 'Somalia', 'ZA': 'South Africa', 'GS': 'South Georgia and the South Sandwich Islands',
'SS': 'South Sudan', 'ES': 'Spain', 'LK': 'Sri Lanka', 'SD': 'Sudan',
'SR': 'Suriname', 'SJ': 'Svalbard and Jan Mayen', 'SE': 'Sweden',
'CH': 'Switzerland', 'SY': 'Syria', 'TW': 'Taiwan', 'TJ': 'Tajikistan',
'TZ': 'Tanzania', 'TH': 'Thailand', 'TL': 'Timor-Leste', 'TG': 'Togo',
'TK': 'Tokelau', 'TO': 'Tonga', 'TT': 'Trinidad and Tobago', 'TN': 'Tunisia',
'TR': 'Turkey', 'TM': 'Turkmenistan', 'TC': 'Turks and Caicos Islands',
'TV': 'Tuvalu', 'UG': 'Uganda', 'UA': 'Ukraine', 'AE': 'United Arab Emirates',
'GB': 'United Kingdom', 'US': 'United States', 'UM': 'United States Minor Outlying Islands',
'UY': 'Uruguay', 'UZ': 'Uzbekistan', 'VU': 'Vanuatu', 'VE': 'Venezuela',
'VN': 'Vietnam', 'VG': 'Virgin Islands (British)', 'VI': 'Virgin Islands (U.S.)',
'WF': 'Wallis and Futuna', 'EH': 'Western Sahara', 'YE': 'Yemen',
'ZM': 'Zambia', 'ZW': 'Zimbabwe'
}
return country_map.get(country_code, country_code)
def parse_coordinates(loc_str):
if not loc_str or ',' not in loc_str:
return 0.0, 0.0, "", ""
lat_str, lon_str = loc_str.split(',')
lat = float(lat_str.strip())
lon = float(lon_str.strip())
def dec_to_dms(dec):
degrees = int(dec)
minutes = int((abs(dec) - abs(degrees)) * 60)
seconds = (abs(dec) - abs(degrees) - minutes/60) * 3600
direction = "N" if dec >= 0 else "S"
return f"{abs(degrees)}° {abs(minutes)}′ {abs(seconds):.2f}″ {direction}"
lat_dms = dec_to_dms(lat)
lon_dms = dec_to_dms(lon).replace("N", "E").replace("S", "W")
return lat, lon, lat_dms, lon_dms
def format_output(ip_str, ip_data):
decimal = ip_to_decimal(ip_str)
hostname = reverse_dns_lookup(ip_str)
lat, lon, lat_dms, lon_dms = parse_coordinates(ip_data.get('loc', '0,0'))
country_code = ip_data.get('country', 'N/A')
country = get_country_name(country_code)
region = ip_data.get('region', 'N/A')
city = ip_data.get('city', 'N/A')
asn = ip_data.get('org', 'N/A').split()[0] if ip_data.get('org') else 'N/A'
isp = ' '.join(ip_data.get('org', 'N/A').split()[1:]) if ip_data.get('org') else 'N/A'
separator = f"{Colors.SEPARATOR}{'='*50}{Colors.RESET}"
print(f"\n{separator}")
print(f"{Colors.HEADER}IP Details For:{Colors.RESET} {ip_str}")
print(f"{separator}")
fields = [
(f"{Colors.LABEL}Decimal:{Colors.RESET}", f" {decimal}"),
(f"{Colors.LABEL}Hostname:{Colors.RESET}", f" {hostname}"),
(f"{Colors.LABEL}ASN:{Colors.RESET}", f" {asn}"),
(f"{Colors.LABEL}ISP:{Colors.RESET}", f" {isp}"),
(f"{Colors.LABEL}Country:{Colors.RESET}", f" {country}"),
(f"{Colors.LABEL}State/Region:{Colors.RESET}", f"{region}"),
(f"{Colors.LABEL}City:{Colors.RESET}", f" {city}"),
(f"{Colors.LABEL}Latitude:{Colors.RESET}", f" {lat:.4f} ({lat_dms})"),
(f"{Colors.LABEL}Longitude:{Colors.RESET}", f" {lon:.4f} ({lon_dms})")
]
for label, value in fields:
print(f"{label:<20} {value}")
print(f"{separator}")
def print_banner():
# SIMPLE SOLUTION: Just print each line directly
print(f"{Colors.HEADER}")
print(" ________ _______ __")
print(" / _/ __ \\/ ____(_)___ ____/ /__ _____")
print(" / // /_/ / /_ / / __ \\/ __ / _ \\/ ___/")
print(" _/ // ____/ __/ / / / / / /_/ / __/ /")
print("/___/_/ /_/ /_/_/ /_/\\__,_/\\___/_/")
print(" By URDev | V1.0")
print(f"{Colors.RESET}")
def main():
parser = argparse.ArgumentParser(description='IPFinder - Passive IP Intelligence Tool', add_help=False)
parser.add_argument('ip', nargs='?', help='Target IP address')
parser.add_argument('-i', '--myip', action='store_true', help='Get current public IP')
parser.add_argument('-n', '--no-color', action='store_true', help='Disable colored output')
parser.add_argument('-h', '--help', action='store_true', help='Show help message')
args = parser.parse_args()
if args.no_color:
disable_colors()
if args.help:
print(f"{Colors.HEADER}IPFinder Usage:{Colors.RESET}")
print(" python ipfinder.py [IP_ADDRESS] # Analyze specific IP")
print(" python ipfinder.py -i # Analyze your public IP")
print(" python ipfinder.py # Interactive mode")
print(" python ipfinder.py -n # Disable colors")
return
print_banner()
target_ip = None
if args.myip:
try:
target_ip = get_public_ip()
print(f"{Colors.LABEL}Detected Public IP:{Colors.RESET} {target_ip}")
except Exception as e:
print(f"{Colors.WARNING}Error: {e}{Colors.RESET}")
return
elif args.ip:
if validate_ip(args.ip):
target_ip = args.ip
else:
print(f"{Colors.WARNING}Invalid IP address: {args.ip} (e.g., use 8.8.8.8 or 192.168.1.1){Colors.RESET}")
return
else:
print(f"{Colors.HEADER}Interactive Mode{Colors.RESET}")
print(f"{Colors.LABEL}Enter IP address (press Enter for your public IP):{Colors.RESET} ", end='')
user_input = input().strip()
if user_input == "":
try:
target_ip = get_public_ip()
print(f"{Colors.LABEL}Detected Public IP:{Colors.RESET} {target_ip}")
except Exception as e:
print(f"{Colors.WARNING}Error: {e}{Colors.RESET}")
return
else:
if validate_ip(user_input):
target_ip = user_input
else:
print(f"{Colors.WARNING}Invalid IP address: {user_input} (e.g., use 8.8.8.8 or 192.168.1.1){Colors.RESET}")
return
# Start loading animation
loader = LoadingAnimation("Fetching data")
loader.start()
# Fetch IP info
ip_data = fetch_ip_info(target_ip)
# Stop loading animation
loader.stop()
if not ip_data:
print(f"{Colors.WARNING}Could not retrieve IP information{Colors.RESET}")
print(f"{Colors.HEADER}Basic Information:{Colors.RESET}")
print(f"{Colors.LABEL}IP:{Colors.RESET} {target_ip}")
print(f"{Colors.LABEL}Decimal:{Colors.RESET} {ip_to_decimal(target_ip)}")
print(f"{Colors.LABEL}Hostname:{Colors.RESET} {reverse_dns_lookup(target_ip)}")
return
format_output(target_ip, ip_data)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print(f"\n{Colors.HEADER}Operation cancelled{Colors.RESET}")
sys.exit(0)
except Exception as e:
print(f"{Colors.WARNING}Unexpected error: {e}{Colors.RESET}")
sys.exit(1)