-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest_direct_nmap.py
More file actions
74 lines (62 loc) · 2.48 KB
/
Copy pathtest_direct_nmap.py
File metadata and controls
74 lines (62 loc) · 2.48 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
#!/usr/bin/env python3
"""
Test script to directly call Nmap and verify it works
"""
import subprocess
import os
import sys
def test_direct_nmap():
"""Test if we can directly call Nmap executable"""
# Define paths to check
nmap_paths = [
"C:\\Program Files (x86)\\Nmap\\nmap.exe",
"C:\\Program Files\\Nmap\\nmap.exe",
"nmap" # Try PATH
]
# Try running each path
for path in nmap_paths:
try:
print(f"Testing path: {path}")
if path == "nmap":
cmd = ["nmap", "--version"]
else:
if not os.path.exists(path):
print(f" Path does not exist: {path}")
continue
cmd = [path, "--version"]
print(f" Running command: {' '.join(cmd)}")
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
print(f" SUCCESS! Nmap found at {path}")
print(f" Version: {result.stdout.splitlines()[0]}")
# Try a simple scan to fully verify
print("\nTesting scan of localhost (127.0.0.1)...")
scan_cmd = cmd[0:-1] + ["-F", "127.0.0.1"]
print(f" Running: {' '.join(scan_cmd)}")
scan_result = subprocess.run(scan_cmd, capture_output=True, text=True)
if scan_result.returncode == 0:
print(" Scan successful!")
return True
else:
print(f" Scan failed: {scan_result.stderr}")
else:
print(f" Failed with: {result.stderr}")
except Exception as e:
print(f" Error testing {path}: {e}")
print("\nUnable to find a working Nmap installation.")
print("Please ensure Nmap is installed and accessible.")
return False
if __name__ == "__main__":
print("=" * 60)
print("Nmap Direct Call Test")
print("=" * 60)
success = test_direct_nmap()
if not success:
print("\nTroubleshooting tips:")
print("1. Reinstall Nmap from https://nmap.org/download.html")
print("2. Make sure the installation path is in your system PATH")
print("3. Try running as administrator")
print("4. Check Windows Defender or antivirus settings")
sys.exit(1)
else:
print("\nNmap test successful. You can use it in your application.")