-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSNmapPy.py
More file actions
553 lines (493 loc) · 17.8 KB
/
SNmapPy.py
File metadata and controls
553 lines (493 loc) · 17.8 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
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
# Code Written By SayyadN
# Update Date : 7-June-2025
# This code is for educational purposes only.
# Use responsibly and ethically.
# Version 2
# Importing necessary libraries
import nmap
import time
import shutil
#For Skip Modeul Error While ROot (Lib aleardy installed)
try:
from google import genai
has_GenAI = True
except ImportError:
has_GenAI = False
import logging
import argparse
from colorama import Fore, Back, init
import os
# Initialize colorama
init(autoreset=True)
# Define aliases for p and input
p = print
i = input
# Configure logging
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
#Function For Root Run
def root_checker():
if os.geteuid() != 0:
p("Please ReRun App With sudo Command - Sudo يرجي تشغيل البرنامج من فضلك باستعمال ")
exit()
# استبدل هذا بمفتاح API خاص بك في بيئة آمنة
API_KEY = "AIzaSyCDXhbDjtMMbKkm0FKGMr3SPAPaQ_aWYBQ"
def ai_help(error_message):
try:
# تهيئة المكتبة
genai.configure(api_key=API_KEY)
model = genai.GenerativeModel("gemini-2.0-flash")
while True:
# إرسال الرسالة إلى نموذج الذكاء الاصطناعي
response = model.generate_content(error_message)
print("\n🔍 رد الذكاء الاصطناعي:")
print(response.text)
# سؤال المستخدم
user_input = input("\nتقدر تخرج لما تكتب 'exit'. هل تريد المزيد من المساعدة؟ (Y/N): ").lower()
if user_input in ["exit", "n"]:
print("🚪 الخروج من المساعد الذكي.")
break
elif user_input == "y":
error_message = input("🧠 أريد المعرفة عن المشكلة التي ظهرت: ")
else:
print("❌ خطأ في الإدخال، حاول مرة أخرى.")
except Exception as ex:
print("⚠️ الذكاء الاصطناعي غير متوفر حاليًا.")
print(f"تفاصيل الخطأ: {ex}")
# --- Utility Functions ---
def ask_continue(message="Do you want to continue? (Y/N): "):
try:
while True:
choice = i(message).strip().lower()
if choice in ['y', 'yes']:
return True
elif choice in ['n', 'no']:
p("Exiting...")
exit(0)
else:
p("Invalid input. Please enter 'Y' or 'N'.")
except Exception as e:
ai_help(str(e))
def check_tool(cmd):
try:
if shutil.which(cmd) is None:
logging.warning(f"'{cmd}' is not installed. Some features may not work correctly.")
return False
return True
except Exception as e:
ai_help(str(e))
# --- Scan Functions ---
def perform_scan(target, arguments, scan_type):
try:
nm = nmap.PortScanner()
nm.scan(target, arguments=arguments)
p(f"{scan_type} scan results for {target}:")
for host in nm.all_hosts():
p(f"Host: {host}")
if 'tcp' in nm[host]:
for port, data in nm[host]['tcp'].items():
p(f" Port: {port}\tState: {data['state']}\tService: {data.get('name', 'Unknown')}")
if 'udp' in nm[host]:
for port, data in nm[host]['udp'].items():
p(f" Port: {port}\tState: {data['state']}\tService: {data.get('name', 'Unknown')}")
except Exception as e:
logging.error(f"Error during {scan_type} scan: {e}")
ai_help(str(e))
ask_continue()
def scan_ports(target):
try:
perform_scan(target, '-sS', 'Port')
except Exception as e:
ai_help(str(e))
def scan_os(target):
try:
nm = nmap.PortScanner()
nm.scan(target, arguments='-O')
p(f"OS scan results for {target}:")
if 'osclass' in nm[target]:
for osclass in nm[target]['osclass']:
p(f"OS Class: {osclass['osfamily']}")
if 'osmatch' in nm[target]:
p(f"OS Match: {nm[target]['osmatch'][0]['name']}")
except Exception as e:
p(f"Error scanning OS: {e}")
ai_help(str(e))
ask_continue()
def scan_services(target):
try:
perform_scan(target, '-sV', 'Service')
except Exception as e:
ai_help(str(e))
def network_mapping(target):
try:
perform_scan(target, '-sn', 'Network Mapping')
except Exception as e:
ai_help(str(e))
def scan_firewall(target):
try:
perform_scan(target, '-sA', 'Firewall')
except Exception as e:
ai_help(str(e))
def scan_vulnerabilities(target):
try:
perform_scan(target, '--script vuln', 'Vulnerability')
except Exception as e:
ai_help(str(e))
def scan_wifi(target):
try:
perform_scan(target, '--script wifi', 'WiFi')
except Exception as e:
ai_help(str(e))
def scan_dns(target):
try:
perform_scan(target, '-sL', 'DNS')
except Exception as e:
ai_help(str(e))
def scan_snmp(target):
try:
perform_scan(target, '-sU -p 161', 'SNMP')
except Exception as e:
ai_help(str(e))
def scan_http(target):
try:
perform_scan(target, '-p 80,443', 'HTTP')
except Exception as e:
ai_help(str(e))
def scan_ftp(target):
try:
perform_scan(target, '-p 21', 'FTP')
except Exception as e:
ai_help(str(e))
def scan_ssh(target):
try:
perform_scan(target, '-p 22', 'SSH')
except Exception as e:
ai_help(str(e))
def scan_telnet(target):
try:
perform_scan(target, '-p 23', 'Telnet')
except Exception as e:
ai_help(str(e))
def scan_smtp(target):
try:
perform_scan(target, '-p 25', 'SMTP')
except Exception as e:
ai_help(str(e))
def scan_pop3(target):
try:
perform_scan(target, '-p 110', 'POP3')
except Exception as e:
ai_help(str(e))
def scan_imap(target):
try:
perform_scan(target, '-p 143', 'IMAP')
except Exception as e:
ai_help(str(e))
def scan_ldap(target):
try:
perform_scan(target, '-p 389', 'LDAP')
except Exception as e:
ai_help(str(e))
def scan_rdp(target):
try:
perform_scan(target, '-p 3389', 'RDP')
except Exception as e:
ai_help(str(e))
def scan_smb(target):
try:
perform_scan(target, '-p 445', 'SMB')
except Exception as e:
ai_help(str(e))
def scan_mysql(target):
try:
perform_scan(target, '-p 3306', 'MySQL')
except Exception as e:
ai_help(str(e))
def scan_postgresql(target):
try:
perform_scan(target, '-p 5432', 'PostgreSQL')
except Exception as e:
ai_help(str(e))
def scan_mongodb(target):
try:
perform_scan(target, '-p 27017', 'MongoDB')
except Exception as e:
ai_help(str(e))
def scan_redis(target):
try:
perform_scan(target, '-p 6379', 'Redis')
except Exception as e:
ai_help(str(e))
def scan_elasticsearch(target):
try:
perform_scan(target, '-p 9200', 'Elasticsearch')
except Exception as e:
ai_help(str(e))
def scan_docker(target):
try:
perform_scan(target, '-p 2375', 'Docker')
except Exception as e:
ai_help(str(e))
def scan_kubernetes(target):
try:
perform_scan(target, '-p 6443', 'Kubernetes')
except Exception as e:
ai_help(str(e))
def scan_ssl(target):
try:
perform_scan(target, '-p 443 --script ssl-enum-ciphers', 'SSL')
except Exception as e:
ai_help(str(e))
def scan_ipv6(target):
try:
perform_scan(target, '-6', 'IPv6')
except Exception as e:
ai_help(str(e))
def scan_ipv4(target):
try:
perform_scan(target, '-4', 'IPv4')
except Exception as e:
ai_help(str(e))
def check_for_updates():
try:
nm = nmap.PortScanner()
nm.scan('localhost', arguments='--script update')
p("Update check results:")
for proto in nm['localhost'].all_protocols():
p(f"Protocol: {proto}")
lport = nm['localhost'][proto].keys()
for port in sorted(lport):
p(f"Port: {port}\tState: {nm['localhost'][proto][port]['state']}")
except Exception as e:
p(f"Error checking for updates: {e}")
ai_help(str(e))
ask_continue()
def scan_wifi_clients(subnet):
try:
nm = nmap.PortScanner()
p(f"Scanning for clients on subnet {subnet}...")
nm.scan(hosts=subnet, arguments='-sn')
p("\nActive Clients on the Network:")
for host in nm.all_hosts():
mac_address = nm[host]['addresses'].get('mac', "Unknown")
hostname = nm[host].hostname() or "No Hostname"
ip_address = nm[host]['addresses'].get('ipv4', "Unknown")
state = nm[host].state()
p(f"IP: {ip_address}\tMAC: {mac_address}\tHostname: {hostname}\tState: {state}")
except Exception as e:
p(f"Error scanning WiFi clients: {e}")
ai_help(str(e))
ask_continue()
def custom_scan(target, arguments):
try:
perform_scan(target, arguments, 'Custom')
except Exception as e:
ai_help(str(e))
# --- Main Function ---
def main():
try:
parser = argparse.ArgumentParser(description="SNmapPy - Network Analysis and WiFi Tool")
parser.add_argument("-t", "--target", help="Target IP address or hostname")
parser.add_argument("-s", "--scan", help="Specific scan to run (e.g., ports, os, services)")
parser.add_argument("-c", "--custom", help="Custom Nmap arguments")
args = parser.parse_args()
p("""
____ _ _ ____
/ ___|| \ | |_ __ ___ __ _ _ __ | _ \ _ _
\___ \| \| | '_ ` _ \ / _` | '_ \| |_) | | | |
___) | |\ | | | | | | (_| | |_) | __/| |_| |
|____/|_| \_|_|_|_| |_|\__,_| .__/|_| \__, | _ _ _
| |__ _ _ / ___| __ _ _|_|_ _ _ _|___/__| | \ | |
| '_ \| | | | \___ \ / _` | | | | | | |/ _` |/ _` | \| |
| |_) | |_| | ___) | (_| | |_| | |_| | (_| | (_| | |\ |
|_.__/ \__, | |____/ \__,_|\__, |\__, |\__,_|\__,_|_| \_|
|___/ |___/ |___/
""")
if args.target and args.scan:
# Run specific scan on target
target = args.target
scan_type = args.scan.lower()
if scan_type == "ports":
scan_ports(target)
elif scan_type == "os":
scan_os(target)
elif scan_type == "services":
scan_services(target)
elif scan_type == "network_mapping":
network_mapping(target)
elif scan_type == "firewall":
scan_firewall(target)
elif scan_type == "vulnerabilities":
scan_vulnerabilities(target)
elif scan_type == "wifi":
scan_wifi(target)
elif scan_type == "dns":
scan_dns(target)
elif scan_type == "snmp":
scan_snmp(target)
elif scan_type == "http":
scan_http(target)
elif scan_type == "ftp":
scan_ftp(target)
elif scan_type == "ssh":
scan_ssh(target)
elif scan_type == "telnet":
scan_telnet(target)
elif scan_type == "smtp":
scan_smtp(target)
elif scan_type == "pop3":
scan_pop3(target)
elif scan_type == "imap":
scan_imap(target)
elif scan_type == "ldap":
scan_ldap(target)
elif scan_type == "rdp":
scan_rdp(target)
elif scan_type == "smb":
scan_smb(target)
elif scan_type == "mysql":
scan_mysql(target)
elif scan_type == "postgresql":
scan_postgresql(target)
elif scan_type == "mongodb":
scan_mongodb(target)
elif scan_type == "redis":
scan_redis(target)
elif scan_type == "elasticsearch":
scan_elasticsearch(target)
elif scan_type == "docker":
scan_docker(target)
elif scan_type == "kubernetes":
scan_kubernetes(target)
elif scan_type == "ssl":
scan_ssl(target)
elif scan_type == "ipv6":
scan_ipv6(target)
elif scan_type == "ipv4":
scan_ipv4(target)
else:
p("Invalid scan type specified.")
return # Exit after running the specific scan
elif args.target and args.custom:
target = args.target
custom_args = args.custom
custom_scan(target, custom_args)
return
while True:
p("\nMain Menu / القائمة الرئيسية:")
p("1. Port Scan / فحص البورتات")
p("2. OS Scan / فحص نظام التشغيل")
p("3. Service Scan / فحص الخدمات")
p("4. Network Mapping / رسم خريطة الشبكة")
p("5. Firewall Scan / فحص الجدار الناري")
p("6. Vulnerability Scan / فحص الثغرات")
p("7. WiFi Scan / فحص الواي فاي")
p("8. DNS Scan / فحص نظام أسماء النطاقات")
p("9. SNMP Scan / فحص SNMP")
p("10. HTTP Scan / فحص HTTP")
p("11. FTP Scan / فحص FTP")
p("12. SSH Scan / فحص SSH")
p("13. Telnet Scan / فحص Telnet")
p("14. SMTP Scan / فحص SMTP")
p("15. POP3 Scan / فحص POP3")
p("16. IMAP Scan / فحص IMAP")
p("17. LDAP Scan / فحص LDAP")
p("18. RDP Scan / فحص RDP")
p("19. SMB Scan / فحص SMB")
p("20. MySQL Scan / فحص MySQL")
p("21. PostgreSQL Scan / فحص PostgreSQL")
p("22. MongoDB Scan / فحص MongoDB")
p("23. Redis Scan / فحص Redis")
p("24. Elasticsearch Scan / فحص Elasticsearch")
p("25. Docker Scan / فحص Docker")
p("26. Kubernetes Scan / فحص Kubernetes")
p("27. Check for Updates / التحقق من التحديثات")
p("28. SSL Scan / فحص SSL")
p("29. IPv6 Scan / فحص IPv6")
p("30. IPv4 Scan / فحص IPv4")
p("31. Scan WiFi Clients / فحص عملاء الواي فاي")
p("32. Custom Scan / فحص مخصص")
p("0. Exit / خروج")
choice = i("\nEnter your choice: ").strip()
if choice == "0":
p("Exiting... Goodbye!")
exit(0)
target = i("Enter the target IP address: ").strip() if choice not in ["27", "31", "32"] else None
try:
if choice == "1":
scan_ports(target)
elif choice == "2":
scan_os(target)
elif choice == "3":
scan_services(target)
elif choice == "4":
network_mapping(target)
elif choice == "5":
scan_firewall(target)
elif choice == "6":
scan_vulnerabilities(target)
elif choice == "7":
scan_wifi(target)
elif choice == "8":
scan_dns(target)
elif choice == "9":
scan_snmp(target)
elif choice == "10":
scan_http(target)
elif choice == "11":
scan_ftp(target)
elif choice == "12":
scan_ssh(target)
elif choice == "13":
scan_telnet(target)
elif choice == "14":
scan_smtp(target)
elif choice == "15":
scan_pop3(target)
elif choice == "16":
scan_imap(target)
elif choice == "17":
scan_ldap(target)
elif choice == "18":
scan_rdp(target)
elif choice == "19":
scan_smb(target)
elif choice == "20":
scan_mysql(target)
elif choice == "21":
scan_postgresql(target)
elif choice == "22":
scan_mongodb(target)
elif choice == "23":
scan_redis(target)
elif choice == "24":
scan_elasticsearch(target)
elif choice == "25":
scan_docker(target)
elif choice == "26":
scan_kubernetes(target)
elif choice == "27":
check_for_updates()
elif choice == "28":
scan_ssl(target)
elif choice == "29":
scan_ipv6(target)
elif choice == "30":
scan_ipv4(target)
elif choice == "31":
subnet = i("Enter subnet (e.g., 192.168.1.0/24): ")
scan_wifi_clients(subnet)
elif choice == "32":
target = i("Enter the target IP address: ").strip()
custom_arguments = i("Enter custom Nmap arguments: ").strip()
custom_scan(target, custom_arguments)
else:
p("Invalid choice, please try again.")
except Exception as e:
p(f"An error occurred: {e}")
ai_help(str(e))
time.sleep(1)
except Exception as e:
ai_help(str(e))
if __name__ == "__main__":
root_checker()
main()