Skip to content

Commit 13186f7

Browse files
committed
fix: nmap path checks
1 parent 2561051 commit 13186f7

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

nmap3/utils.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_nmap_path(path:str='') -> str:
3838
by calling which nmap
3939
If not found raises NmapNotInstalledError
4040
"""
41-
if (os.path.exists(path)):
41+
if path and (os.path.exists(path)):
4242
return path
4343

4444
os_type = sys.platform
@@ -49,17 +49,15 @@ def get_nmap_path(path:str='') -> str:
4949
args = shlex.split(cmd)
5050
sub_proc = subprocess.Popen(args, stdout=subprocess.PIPE)
5151

52-
try:
53-
output, _ = sub_proc.communicate(timeout=15)
54-
except Exception as e:
52+
output, e = sub_proc.communicate(timeout=15)
53+
if e:
5554
print(e)
56-
sub_proc.kill()
55+
56+
if not output:
5757
raise NmapNotInstalledError(path=path)
58-
else:
59-
if os_type == 'win32':
60-
return output.decode('utf8').strip().replace("\\", "/")
61-
else:
62-
return output.decode('utf8').strip()
58+
if os_type == 'win32':
59+
return output.decode('utf8').strip().replace("\\", "/")
60+
return output.decode('utf8').strip()
6361

6462
def get_nmap_version():
6563
nmap = get_nmap_path()

0 commit comments

Comments
 (0)