我们的计划是检查打开的端口,即使库已经安装并且我正在使用anacond,但我的nmap出错了。
import socket, subprocess, re
s = socket.socket()
host = socket.gethostname()
nmap_lst_out = []
s = socket.socket()
print ('The Name of the Local Machine:-',host)
print ('\n' * 2)
print ('*' * 60)
print('PLEASE WAIT SCANNING THE REMOTE HOST {} AT {}'.format(host,socket.gethostbyname('localhost')))
print ('*' * 60)
for port in range(1,1024):
try:
s.connect((host,port))
open_port = socket.getservbyport(port)
print ('PORT {0} OPEN'.format(open_port))
s.close()
s = socket.socket()
except:
print ("\r+",end="")
nmap_out = subprocess.check_output(['nmap','Saujan'])
nmap_out = str(nmap_out)
nmap_out = nmap_out.split('\\n')
for i in nmap_out:
out = re.search('(open\s+)([a-zA-Z]+)',i)
if out:
nmap_lst_out.append(out.group(2))
print ('NMAP OPEN PORT:-',out.group(2))`我也已经安装了这个软件包。
已安装的软件包
Saujan:Project $ pip安装nmap要求已经满足: nmap in /anaconda3 3/lib/python3.7 3.7/site-packages (0.0.1)
发布于 2020-06-25 17:35:21
即使安装了nmap,也不能执行它,只要不在路径目录中运行它。因此,首先您应该导航到安装nmap的目录,然后尝试运行它。
发布于 2021-06-10 14:47:07
apt-get install nmap -基于Debian的,如Debian,Ubuntu等.yum install nmap -用于Centos/RedHat发行版。brew install nmap - On MacOSsubprocess.Popen而不是subprocess.check_output。import subprocess
p = subprocess.Popen(['nmap', 'Saujan'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = p.communicate()
for i in output.readlines():
# Use your regular expressions...https://stackoverflow.com/questions/55206719
复制相似问题