-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
1070 lines (898 loc) · 38.9 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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
import os
import urllib.request
import json
from platform import system
import sys
from datetime import datetime
import time
import readline
import socket
import ipaddress
import math
import random
import string
import psutil
import nmap
import requests
from uuid import getnode as get_mac
def slowprint(s, delay=1./400, newline=True):
for c in s:
sys.stdout.write(c)
sys.stdout.flush()
time.sleep(delay)
if newline:
sys.stdout.write('\n')
sys.stdout.flush()
def ipinfo():
while True:
try:
os.system("clear")
os.system("figlet IP Scanner")
print(" ")
ip = input("\033[1;33mEnter IP Address: \033[1;91m")
if ip.strip() == "":
return
try:
ip_addr = ipaddress.ip_address(ip)
if ip_addr.is_private:
print(" ")
print("\033[1;31mError: Please enter a public IP address.\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
continue
except ValueError:
print(" ")
print("\033[1;31mError: Invalid IP address.\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
continue
url = "http://ip-api.com/json/"
response = urllib.request.urlopen(url + ip)
data = response.read()
values = json.loads(data)
slowprint(" ")
slowprint("\033[1;36m" + "IP : \033[1;32m" + values['query'])
slowprint("\033[1;36m" + "Status : \033[1;32m" + values['status'])
slowprint("\033[1;36m" + "Region : \033[1;32m" + values['regionName'])
slowprint("\033[1;36m" + "Country : \033[1;32m" + values['country'])
slowprint("\033[1;36m" + "Date & Time : \033[1;32m" + datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
slowprint("\033[1;36m" + "City : \033[1;32m" + values['city'])
slowprint("\033[1;36m" + "ISP : \033[1;32m" + values['isp'])
slowprint("\033[1;36m" + "Lat, Lon : \033[1;32m" + str(values['lat']) + ", " + str(values['lon']))
slowprint("\033[1;36m" + "ZIPCODE : \033[1;32m" + values['zip'])
slowprint("\033[1;36m" + "TimeZone : \033[1;32m" + values['timezone'])
slowprint("\033[1;36m" + "AS : \033[1;32m" + values['as'] + "\n")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
def dns_lookup():
while True:
try:
print("\033[1;36m")
os.system("figlet DNS Lookup")
print(" ")
domain = input("\033[1;33mEnter a domain name (e.g., example.com):\033[0m ")
ip_address = socket.gethostbyname(domain)
slowprint(f"\033[1;33mThe IP address for \033[1;91m{domain} \033[1;33mis: \033[1;91m{ip_address}\033[0m")
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except socket.gaierror:
os.system("clear")
try:
slowprint(f"\033[1;91mError: \033[1;33mUnable to resolve the domain \033[1;91m{domain}\033[0m")
print(" ")
input("\033[1;33m [+] Press Enter To Retry [+]\033[0m")
os.system("clear")
continue
except KeyboardInterrupt:
os.system("clear")
return
except KeyboardInterrupt:
os.system("clear")
return
except Exception as e:
os.system("clear")
try:
slowprint(f"\033[1;91mAn unexpected error occurred: \033[1;33m{e}\033[0m")
print(" ")
input("\033[1;33m [+] Press Enter To Retry [+]\033[0m")
os.system("clear")
continue
except KeyboardInterrupt:
os.system("clear")
return
def ip_to_subnets():
while True:
try:
os.system("clear")
print("\033[1;36m")
os.system("figlet Subnet Divider")
print(" ")
ip_input = input("\033[1;33mEnter an IP address (e.g., 10.1.1.0/24): \033[1;91m")
network = ipaddress.IPv4Network(ip_input, strict=False)
num_subnets = int(input("\033[1;33mEnter the number of subnets to create: \033[1;91m"))
if num_subnets <= 0:
raise ValueError("Number of subnets must be a positive integer.")
new_prefix = network.prefixlen + math.ceil(math.log2(num_subnets))
if new_prefix > 32:
raise ValueError("The number of subnets exceeds the available address space.")
num_possible_subnets = 2**(new_prefix - network.prefixlen)
subnet_mask = ipaddress.IPv4Network(f"0.0.0.0/{new_prefix}").netmask
slowprint(f"\n\033[1;33mTo create {num_subnets} subnets, the new subnet mask will be: \033[1;91m{subnet_mask}\033[0m")
slowprint(f"\033[1;33mYou can create up to {num_possible_subnets} subnets with this configuration.\033[0m\n")
table_color = "\033[1;35m"
slowprint(table_color + "{:<10} {:<20} {:<20} {:<20} {:<20}".format("Subnet", "Network Address", "First Host", "Last Host", "Broadcast Address"))
slowprint(table_color + "-" * 90)
subnets = list(network.subnets(new_prefix=new_prefix))
for i, subnet in enumerate(subnets, 1):
first_ip = subnet.network_address + 1
last_ip = subnet.broadcast_address - 1
print(table_color + "{:<10} {:<20} {:<20} {:<20} {:<20}".format(i, str(subnet.network_address), str(first_ip), str(last_ip), str(subnet.broadcast_address)))
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]\033[1;91m")
os.system("clear")
except ValueError as e:
slowprint(f"\033[1;31mError: {e}\033[0m")
slowprint("\033[1;31mPlease enter a valid IP address and subnet number.\033[0m")
input("\n\033[1;33mPress Enter to try again...\033[0m")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
except Exception as e:
slowprint(f"\033[1;31mAn unexpected error occurred: {e}\033[0m")
slowprint("\033[1;31mPlease enter a valid IP address and subnet number.\033[0m")
input("\n\033[1;33mPress Enter to try again...\033[0m")
os.system("clear")
def ip_to_binary():
while True:
try:
print("\033[1;36m")
os.system("figlet Ip to Binary")
print(" ")
ip_cidr = input("\033[1;33mPlease enter a IP address with CIDR notation (e.g., 192.168.2.22/24):\033[0m ")
if '/' not in ip_cidr:
os.system("clear")
try:
slowprint("\033[1;91mError: \033[1;33mYou forgot to include the CIDR notation. Please try again.\033[0m")
magas = input("\n\033[1;33m [+] Press Enter To Retry [+]\033[0m")
os.system("clear")
continue
except KeyboardInterrupt:
os.system("clear")
return
if is_valid_ip_cidr(ip_cidr):
ip, cidr = ip_cidr.split('/')
cidr = int(cidr)
mask = cidr_to_subnet_mask(cidr)
print(" ")
slowprint(f"\033[1;33mOriginal value:\033[1;91m {ip}/{cidr}\033[0m")
slowprint(f"\033[1;33mMask:\033[1;91m {mask}\033[0m")
signed_ip_bin = signed_binary_ip(ip, cidr)
ip_bin = ip_to_binary_func(ip)
signed_mask_bin = signed_binary_mask(cidr)
mask_bin = ip_to_binary_func(mask)
slowprint(f"\033[1;33mSigned IP Binary:\033[1;91m {signed_ip_bin}\033[0m")
slowprint(f"\033[1;33mIP Binary:\033[1;91m {ip_bin}\033[0m")
slowprint(f"\033[1;33mSigned Mask Binary:\033[1;91m {signed_mask_bin}\033[0m")
slowprint(f"\033[1;33mMask Binary:\033[1;91m {mask_bin}\033[0m")
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]\033[0m")
os.system("clear")
else:
os.system("clear")
try:
slowprint("\033[1;91mError: \033[1;33mInvalid IP address or CIDR notation. Please try again.\033[0m")
input("\n\033[1;33m [+] Press Enter To Retry [+]\033[0m")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
except KeyboardInterrupt:
os.system("clear")
return
def is_valid_ip_cidr(ip_cidr):
try:
ipaddress.ip_interface(ip_cidr)
return True
except ValueError:
return False
def cidr_to_subnet_mask(cidr):
return str(ipaddress.IPv4Network(f'0.0.0.0/{cidr}').netmask)
def ip_to_binary_func(ip):
return '.'.join(format(int(octet), '08b') for octet in ip.split('.'))
def signed_binary_ip(ip, cidr):
binary_ip = ip_to_binary_func(ip).split('.')
full_octets = cidr // 8
remaining_bits = cidr % 8
for i in range(4):
if i < full_octets:
binary_ip[i] = binary_ip[i]
else:
binary_ip[i] = binary_ip[i][:remaining_bits]
return '.'.join(binary_ip)
def signed_binary_mask(cidr):
mask = cidr_to_subnet_mask(cidr)
return signed_binary_ip(mask, cidr)
def generate_password(length, use_uppercase, use_lowercase, use_special):
characters = ""
if use_uppercase:
characters += string.ascii_uppercase
if use_lowercase:
characters += string.ascii_lowercase
if use_special:
characters += string.punctuation
if not characters:
raise ValueError("At least one character type must be selected.")
password = ''.join(random.choice(characters) for _ in range(length))
return password
def password_generator():
while True:
try:
os.system("clear")
os.system("figlet Password Generator")
print(" ")
length = int(input("\033[1;33mEnter the length of the password (1-100): \033[0m"))
if length < 1 or length > 100:
raise ValueError("Length must be between 1 and 100.")
use_uppercase = input("\033[1;33mInclude uppercase letters? (y/n): \033[0m").strip().lower() == 'y'
use_lowercase = input("\033[1;33mInclude lowercase letters? (y/n): \033[0m").strip().lower() == 'y'
use_special = input("\033[1;33mInclude special characters? (y/n): \033[0m").strip().lower() == 'y'
password = generate_password(length, use_uppercase, use_lowercase, use_special)
slowprint(f"\033[1;32mGenerated Password: \033[1;91m{password}\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except ValueError as e:
os.system("clear")
try:
slowprint(f"\033[1;31mError: {e}\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
except KeyboardInterrupt:
os.system("clear")
return
except Exception as e:
os.system("clear")
try:
slowprint(f"\033[1;31mAn unexpected error occurred: {e}\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
def port_scanner():
while True:
try:
print("\033[1;36m")
os.system("figlet Port Scanner")
print(" ")
target = input("\033[1;33mEnter the target IP address or hostname: \033[1;91m")
port_range = input("\033[1;33mEnter the port range to scan (e.g., '20-80'): \033[1;91m")
nm = nmap.PortScanner()
slowprint(f"\n\033[1;34mScanning {target} for open ports in range {port_range}...\033[0m")
nm.scan(target, port_range)
for host in nm.all_hosts():
slowprint(f"\n\033[1;33mHost: \033[1;91m{host} ({nm[host].hostname()})\033[0m")
slowprint(f"\033[1;33mState: \033[1;91m{nm[host].state()}\033[0m")
for protocol in nm[host].all_protocols():
slowprint(f"\033[1;33mProtocol: \033[1;91m{protocol}\033[0m")
ports = nm[host][protocol].keys()
for port in sorted(ports):
port_state = nm[host][protocol][port]['state']
slowprint(f"\033[1;33mPort: \033[1;91m{port}\t\033[1;33mState: \033[1;91m{port_state}\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except Exception as e:
os.system("clear")
slowprint(f"\033[1;31mError occurred: {str(e)}\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
def whois_lookup():
while True:
try:
print("\033[1;36m")
os.system("figlet WHOIS Lookup")
print(" ")
domain = input("\033[1;33mEnter a domain to look up: \033[1;91m")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("whois.iana.org", 43))
s.send(f"{domain}\r\n".encode())
response = s.recv(4096).decode()
s.close()
slowprint(f"\n\033[1;33mWHOIS Response:\n\033[1;91m{response}\033[0m")
magas = input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
if magas == "":
continue
else:
break
except KeyboardInterrupt:
os.system("clear")
return
except Exception as e:
os.system("clear")
try:
slowprint(f"\033[1;31mAn error occurred: {str(e)}\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
def format_bytes(size):
# 2**10 = 1024
power = 1024
n = 0
power_labels = {0: '', 1: 'K', 2: 'M', 3: 'G', 4: 'T'}
while size > power:
size /= power
n += 1
return f"{size:.2f} {power_labels[n]}B"
def network_monitor():
while True:
try:
os.system("clear")
total_sent = 0
total_recv = 0
initial_value = psutil.net_io_counters()
old_value = initial_value
while True:
new_value = psutil.net_io_counters()
sent = new_value.bytes_sent - old_value.bytes_sent
recv = new_value.bytes_recv - old_value.bytes_recv
total_sent += sent
total_recv += recv
old_value = new_value
print("\033[2J\033[H", end="")
print("\033[1;33m [+] Press Ctrl+C to stop monitoring")
print("\033[1;32m")
print(f"\033[1;34mNetwork Monitoring:\033[0m")
print(f"\033[1;32mTotal Bytes Sent: \033[1;91m{format_bytes(total_sent)}\033[0m")
print(f"\033[1;32mTotal Bytes Received: \033[1;91m{format_bytes(total_recv)}\033[0m")
print(f"\033[1;32mPackets Sent: \033[1;91m{new_value.packets_sent - initial_value.packets_sent}\033[0m")
print(f"\033[1;32mPackets Received: \033[1;91m{new_value.packets_recv - initial_value.packets_recv}\033[0m")
print(f"\033[1;32mErrors In: \033[1;91m{new_value.errin - initial_value.errin}\033[0m")
print(f"\033[1;32mErrors Out: \033[1;91m{new_value.errout - initial_value.errout}\033[0m")
print(f"\033[1;32mDropped Packets In: \033[1;91m{new_value.dropin - initial_value.dropin}\033[0m")
print(f"\033[1;32mDropped Packets Out: \033[1;91m{new_value.dropout - initial_value.dropout}\033[0m")
time.sleep(1)
except KeyboardInterrupt:
slowprint("\n\033[1;31m Monitoring stopped.\033[0m")
print("")
try:
magas = input("\033[1;33m [+] Press Enter to restart or Ctrl+C to return [+] \033[0m")
if magas == "":
continue
except KeyboardInterrupt:
break
os.system("clear")
return
def cidr_to_mask(cidr_input):
try:
cidr = int(cidr_input)
except ValueError:
return "Error: Invalid input. Please enter a number between 0 and 32."
if cidr > 32 or cidr < 0:
return "Error: CIDR value must be between 0 and 32."
mask = []
y = 0
z = [1] * cidr
for i in range(len(z)):
math = i % 8
if math == 0:
if i >= 8:
mask.append(y)
y = 0
y += pow(2, 7 - math)
mask.append(y)
[mask.append(0) for _ in range(4 - len(mask))]
mask = ".".join([str(i) for i in mask])
return mask
def run_cidr_to_mask():
try:
while True:
os.system("clear")
print("\033[1;36m")
os.system("figlet cidr to Mask")
print(" ")
cidr_input = input("\033[1;33mEnter a CIDR value (e.g., 24) or press Enter to exit: \033[1;91m")
if not cidr_input:
break
mask = cidr_to_mask(cidr_input)
if "Error" in mask:
slowprint(f"\033[1;31m{mask}\033[0m")
else:
slowprint(f"\033[1;33mThe subnet mask for CIDR /{cidr_input} is: \033[1;91m{mask}\033[0m")
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]\033[1;91m")
except KeyboardInterrupt:
os.system("clear")
return
def mask_to_cidr(mask):
try:
binary_str = ''.join([bin(int(x)).lstrip('0b').zfill(8) for x in mask.split('.')])
except ValueError:
return "Error: Invalid subnet mask format."
if len(mask.split('.')) != 4 or any(int(octet) > 255 for octet in mask.split('.')):
return "Error: Subnet mask must be in the format X.X.X.X with each octet between 0 and 255."
cidr = str(binary_str.count('1'))
if int(cidr) > 32 or int(cidr) < 0:
return "Error: Subnet mask results in an invalid CIDR value."
return cidr
def run_mask_to_cidr():
try:
while True:
os.system("clear")
print("\033[1;36m")
os.system("figlet mask to cidr")
print(" ")
mask_input = input("\033[1;33mEnter a subnet mask (e.g., 255.255.255.0) or press Enter to exit: \033[1;91m")
if not mask_input:
break
cidr = mask_to_cidr(mask_input)
if "Error" in cidr:
slowprint(f"\033[1;31m{cidr}\033[0m")
else:
slowprint(f"\033[1;33mThe CIDR notation for subnet mask {mask_input} is: \033[1;91m/{cidr}\033[0m")
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]\033[1;91m")
except KeyboardInterrupt:
os.system("clear")
return
def binary_to_ip(binary):
octets = binary.split('.')
ip = '.'.join(str(int(octet, 2)) for octet in octets)
return ip
def is_valid_binary(binary):
octets = binary.split('.')
if len(octets) != 4:
return False
for octet in octets:
if len(octet) != 8 or not all(bit in '01' for bit in octet):
return False
return True
def run_binary_to_ip():
try:
while True:
os.system("clear")
print("\033[1;36m")
os.system("figlet Binary to IP")
print(" ")
binary_input = input("\033[1;33mEnter a binary IP (e.g., 11000000.10101000.00000001.00000001) or press Enter to exit: \033[1;91m")
if not binary_input:
break
if is_valid_binary(binary_input):
ip = binary_to_ip(binary_input)
slowprint(f"\033[1;33mThe IP address for binary {binary_input} is:\033[1;91m {ip}")
else:
slowprint("\033[1;33mError:\033[1;91m Invalid binary IP format. Please enter in the format 8.8.8.8, with each octet as an 8-bit binary number.")
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]\033[1;91m")
except KeyboardInterrupt:
os.system("clear")
return
def ipv4_to_ipv6(ipv4_address):
try:
ipv4 = ipaddress.IPv4Address(ipv4_address)
ipv6 = ipaddress.IPv6Address('::ffff:' + str(ipv4))
return str(ipv6)
except ipaddress.AddressValueError:
return "Invalid IPv4 address"
def ipv6_to_ipv4(ipv6_address):
try:
ipv6 = ipaddress.IPv6Address(ipv6_address)
if ipv6.ipv4_mapped:
return str(ipv6.ipv4_mapped)
else:
return "IPv6 address does not map to an IPv4 address"
except ipaddress.AddressValueError:
return "Invalid IPv6 address"
def validate_ip(ip_address):
try:
ipaddress.ip_address(ip_address)
return True
except ValueError:
return False
def run_ipv4_to_ipv6():
while True:
try:
print("\033[1;36m")
os.system("figlet ipv4 to ipv6")
print(" ")
ipv4_address = input("\033[1;33mEnter an IPv4 address: \033[1;91m")
if ipv4_address == "":
continue
ipv4 = ipaddress.IPv4Address(ipv4_address)
ipv6_address = ipaddress.IPv6Address('::ffff:' + ipv4_address)
ipv6_compressed = str(ipv6_address)
ipv6_expanded_short = ipv6_address.exploded
ipv6_expanded_full = ipv6_expanded_short.replace('0000', '0')
print(" ")
slowprint("\033[1;33m IPV6 Compressed:\033[1;91m " + ipv6_compressed)
slowprint("\033[1;33m IPV6 Expanded (Shortened):\033[1;91m " + ipv6_expanded_full)
slowprint("\033[1;33m IPV6 Expanded:\033[1;91m " + ipv6_expanded_short)
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]")
os.system("clear")
except ipaddress.AddressValueError:
try:
print(" ")
slowprint("Invalid IPv4 address")
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
except KeyboardInterrupt:
os.system("clear")
return
def run_ipv6_to_ipv4():
while True:
try:
print("\033[1;36m")
os.system("figlet ipv6 to ipv4")
print(" ")
ipv6_address = input("\033[1;33mEnter an IPv6 address: \033[1;91m")
if ipv6_address == "":
continue
ipv6 = ipaddress.IPv6Address(ipv6_address)
ipv4_mapped = ipv6.ipv4_mapped
if ipv4_mapped:
slowprint(f"\033[1;33mIPv4 address:\033[1;91m {ipv4_mapped}")
else:
slowprint("\033[1;33mThis IPv6 address does not map to an IPv4 address.\033[1;91m")
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]\033[1;91m")
os.system("clear")
except ipaddress.AddressValueError:
try:
slowprint("\033[1;33mInvalid IPv6 address\033[1;91m")
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]\033[1;91m")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
except KeyboardInterrupt:
os.system("clear")
return
def ipv4_subnet_calculator():
while True:
try:
print("\033[1;36m")
os.system("figlet IPv4 Subnet Calculator")
print(" ")
ipv4_input = input("\033[1;33mEnter an IPv4 address with CIDR (e.g., 192.0.3.171/27): \033[0m")
print(" ")
if ipv4_input == "":
continue
network = ipaddress.IPv4Network(ipv4_input, strict=False)
ip = ipaddress.IPv4Address(ipv4_input.split('/')[0])
netmask = network.netmask
network_address = network.network_address
broadcast_address = network.broadcast_address
host_min = network_address + 1
host_max = broadcast_address - 1
num_hosts = network.num_addresses
usable_hosts = max(num_hosts - 2, 0)
wildcard_mask = ipaddress.IPv4Address(int(ipaddress.IPv4Address('255.255.255.255')) - int(netmask))
first_octet = int(str(ip).split('.')[0])
if first_octet >= 1 and first_octet <= 126:
ip_class = "A"
elif first_octet >= 128 and first_octet <= 191:
ip_class = "B"
elif first_octet >= 192 and first_octet <= 223:
ip_class = "C"
elif first_octet >= 224 and first_octet <= 239:
ip_class = "D (Multicast)"
else:
ip_class = "E (Reserved)"
if ip.is_private:
ip_type = "Private"
else:
ip_type = "Public"
slowprint(f"\033[1;33mAddress: \033[1;91m {ip}/{network.prefixlen}")
slowprint(f"\033[1;33mNetmask: \033[1;91m {netmask} = {network.prefixlen}")
slowprint(f"\033[1;33mWildcard Mask: \033[1;91m {wildcard_mask}")
slowprint(f"\033[1;33mNetwork: \033[1;91m {network_address}/{network.prefixlen}")
slowprint(f"\033[1;33mHostMin: \033[1;91m {host_min}")
slowprint(f"\033[1;33mHostMax: \033[1;91m {host_max}")
slowprint(f"\033[1;33mBroadcast: \033[1;91m {broadcast_address}")
slowprint(f"\033[1;33mHosts/Net: \033[1;91m {num_hosts}")
slowprint(f"\033[1;33mUsable Hosts: \033[1;91m {usable_hosts}")
slowprint(f"\033[1;33mIP Type: \033[1;91m {ip_type}")
slowprint(f"\033[1;33mIP Class: \033[1;91m {ip_class}")
slowprint(f"\033[1;33mPTR RR name: \033[1;91m {ip.reverse_pointer}")
slowprint(f"\033[1;33mIPv6 repr: \033[1;91m {ipaddress.IPv6Address('2002::' + str(ip))}")
slowprint(f"\033[1;33mIP version: \033[1;91m {ip.version}")
print(" ")
input("\033[1;33m [+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except ValueError as e:
os.system("clear")
try:
slowprint(f"\033[1;31mError: {e}\033[0m")
print(" ")
magas = input("\033[1;33m [+] Press Enter To Retry [+]")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
except KeyboardInterrupt:
os.system("clear")
return
except Exception as e:
os.system("clear")
try:
slowprint(f"An unexpected error occurred: {e}")
print(" ")
magas = input("\033[1;33m [+] Press Enter To Retry [+]")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
def ipv6_subnet_calculator():
while True:
try:
print("\033[1;36m")
os.system("figlet IPv6 Subnet Calculator")
print(" ")
ipv6_input = input("\033[1;33mEnter an IPv6 address with CIDR (e.g., 2001:db8::/32):\033[0m ")
if ipv6_input == "":
continue
network = ipaddress.IPv6Network(ipv6_input, strict=False)
ip = ipaddress.IPv6Address(ipv6_input.split('/')[0])
netmask = network.prefixlen
network_address = network.network_address
broadcast_address = network.broadcast_address
host_min = network_address + 1
host_max = broadcast_address - 1
num_hosts = network.num_addresses
ipv4_repr = ip.ipv4_mapped if ip.ipv4_mapped else "No IPv4 representation"
ptr_rr_name = ip.reverse_pointer
slowprint(f"\033[1;33mAddress: \033[1;91m {ip}/{netmask}")
slowprint(f"\033[1;33mNetmask: \033[1;91m {network.netmask} = {netmask}")
slowprint(f"\033[1;33mNetwork: \033[1;91m {network_address}/{netmask}")
slowprint(f"\033[1;33mHostMin: \033[1;91m {host_min}")
slowprint(f"\033[1;33mHostMax: \033[1;91m {host_max}")
slowprint(f"\033[1;33mBroadcast: \033[1;91m {broadcast_address}")
slowprint(f"\033[1;33mHosts/Net: \033[1;91m {num_hosts}")
slowprint(f"\033[1;33mIPv4 repr: \033[1;91m {ipv4_repr}")
slowprint(f"\033[1;33mPTR RR name:\033[1;91m {ptr_rr_name}")
slowprint(f"\033[1;33mIP version: \033[1;91m {ip.version}")
slowprint(" ")
magas = input("\033[1;33m [+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except ValueError as e:
os.system("clear")
try:
slowprint(f"Error: {e}")
print(" ")
magas = input("\033[1;33m [+] Press Enter To Retry [+]")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
except KeyboardInterrupt:
os.system("clear")
return
except Exception as e:
os.system("clear")
try:
slowprint(f"An unexpected error occurred: {e}")
print(" ")
magas = input("\033[1;33m [+] Press Enter To Retry [+]")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
def get_network_info():
while True:
try:
os.system("clear")
os.system("figlet Network Info")
print(" ")
mac_address = ':'.join(("%012X" % get_mac())[i:i+2] for i in range(0, 12, 2))
public_ip = requests.get('https://api.ipify.org').text
network_info = {}
for interface_name, interface_addresses in psutil.net_if_addrs().items():
ipv4_address = None
ipv6_address = None
subnet_mask = None
mac = None
for address in interface_addresses:
if address.family == socket.AF_INET:
ipv4_address = address.address
subnet_mask = address.netmask
elif address.family == socket.AF_INET6:
ipv6_address = address.address
elif address.family == psutil.AF_LINK:
mac = address.address
stats = psutil.net_if_stats()[interface_name]
is_up = stats.isup
mtu = stats.mtu
speed = stats.speed
network_info[interface_name] = {
'IPv4 Address': ipv4_address,
'Subnet Mask': subnet_mask,
'IPv6 Address': ipv6_address,
'MAC Address': mac,
'Is Up': is_up,
'MTU': mtu,
'Speed (Mbps)': speed
}
slowprint(f"\033[1;32mPublic IP Address: \033[1;91m{public_ip}\033[0m")
slowprint(f"\033[1;32mMAC Address: \033[1;91m{mac_address}\033[0m")
print("\n\033[1;32mNetwork Interfaces:\033[0m")
for interface_name, details in network_info.items():
slowprint(f"\033[1;33m Interface: \033[1;91m{interface_name}\033[0m")
for key, value in details.items():
slowprint(f"\033[1;32m {key}: \033[1;91m{value}\033[0m")
print("\n\033[1;32mDefault Gateway and DNS Servers:\033[0m")
gateways = psutil.net_if_stats()
for gname, ginfo in gateways.items():
slowprint(f"\033[1;33m Gateway: \033[1;91m{gname}\033[0m, \033[1;32mInfo: \033[1;91m{ginfo}\033[0m")
for key, value in ginfo._asdict().items():
slowprint(f"\033[1;32m {key}: \033[1;91m{value}\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
return
except KeyboardInterrupt:
os.system("clear")
return
except Exception as e:
os.system("clear")
try:
slowprint(f"\033[1;31mAn error occurred: {str(e)}\033[0m")
print(" ")
input("\033[1;33m[+] Press Enter To Continue [+]\033[0m")
os.system("clear")
except KeyboardInterrupt:
os.system("clear")
return
def about():
try:
os.system("clear")
print ("\033[1;32m\007\n")
os.system("figlet Sys Tools")
print("")
slowprint ("\033[1;91m -----------------------------------------------")
slowprint ("\033[1;33m" + " [+] Tool Name =>\033[1;36m" + " Sys Tools")
slowprint ("\033[1;33m" + " [+] Author =>\033[1;36m" + " fruitsaladchan ")
slowprint ("\033[1;33m" + " [+] Latest Update =>\033[1;36m" + " 29/8/2024")
slowprint ("\033[1;33m" + " [+] Github =>\033[1;36m" + " Github.com/fruitsaladchan")
slowprint ("\033[1;91m -----------------------------------------------")
print(" ")
magas = input("\033[1;33m [+] Press Enter To Continue [+]")
os.system("clear")
return
except KeyboardInterrupt:
os.system("clear")
return
def ext():
slowprint ("\033[1;36m ==============================================")
slowprint ("\033[1;33m | Thanks For Using Sys Tools |")
slowprint ("\033[1;36m ==============================================")
print(" ")
exit()
def main():
while True:
try:
os.system("clear")
print("\033[1;36m")
os.system("figlet Sys Tools")
slowprint(" ")
column1 = [
"\033[1;33m [ 1 ]\033[1;91m Public IP scanner",
"\033[1;33m [ 2 ]\033[1;91m DNS Lookup",
"\033[1;33m [ 3 ]\033[1;91m ipv4 Subnet divider",
"\033[1;33m [ 4 ]\033[1;91m IP to Binary",
"\033[1;33m [ 5 ]\033[1;91m Binary to IP",
"\033[1;33m [ 6 ]\033[1;91m Generate Password",
"\033[1;33m [ 7 ]\033[1;91m Port Scanner",
"\033[1;33m [ 8 ]\033[1;91m WHOIS Lookup",
]
column2 = [
"\033[1;33m [ 9 ]\033[1;91m Network Monitor",
"\033[1;33m [ 10 ]\033[1;91m IPv4 to IPv6",
"\033[1;33m [ 11 ]\033[1;91m IPv6 to IPv4",
"\033[1;33m [ 12 ]\033[1;91m CIDR to Mask",
"\033[1;33m [ 13 ]\033[1;91m Mask to CIDR",
"\033[1;33m [ 14 ]\033[1;91m ipv4 subnet Calculator",
"\033[1;33m [ 15 ]\033[1;91m ipv6 subnet Calculator",
"\033[1;33m [ 16 ]\033[1;91m Network Info",
]
for i in range(len(column1)):
slowprint(f"{column1[i]:<50} {column2[i]}")
print(" ")
slowprint(f"\033[1;33m [ 0 ]\033[1;91m About This Tool{' ' * 14}\033[1;33m [ 00 ]\033[1;91m Exit")
print(" ")
option = input("\033[1;36m [+] SysTools >> \033[1;32m")
if option == "1":
os.system("clear")
ipinfo()
elif option == "2":
os.system("clear")
dns_lookup()
elif option == "3":
os.system("clear")
ip_to_subnets()
elif option == "4":
os.system("clear")
ip_to_binary()
elif option == "5":
os.system("clear")