Python使用nmap進行埠掃瞄

2021-10-04 12:21:04 字數 3062 閱讀 8313

python 3.x版本的nmap

python 2.x版本的nmap

先cd進入到解壓的nmap裡面

e:\python\python-nmap-0.1.4\python-nmap-0.1.4>

再執行乙個安裝的操作(注意路徑):

e:\python\python-nmap-0.1.4\python-nmap-0.1.4>c:\python27\python setup.py install

running install

running build

running build_py

creating build

creating build\lib

creating build\lib\nmap

copying nmap\example.py -> build\lib\nmap

copying nmap\nmap.py -> build\lib\nmap

copying nmap\__init__.py -> build\lib\nmap

running install_lib

creating c:\python27\lib\site-packages\nmap

copying build\lib\nmap\example.py -> c:\python27\lib\site-packages\nmap

copying build\lib\nmap\nmap.py -> c:\python27\lib\site-packages\nmap

copying build\lib\nmap\__init__.py -> c:\python27\lib\site-packages\nmap

byte-compiling c:\python27\lib\site-packages\nmap\example.py to example.pyc

byte-compiling c:\python27\lib\site-packages\nmap\nmap.py to nmap.pyc

byte-compiling c:\python27\lib\site-packages\nmap\__init__.py to __init__.pyc

running install_egg_info

writing c:\python27\lib\site-packages\python_nmap-0.1.4-py2.7.egg-info

報錯

traceback (most recent call last):

file "e:\python\1.py", line 3, in

nm=nmap.portscanner()

file "c:\python27\lib\site-packages\nmap\nmap.py", line 118, in __init__

p = subprocess.popen(['nmap', '-v'], bufsize=10000, stdout=subprocess.pipe)

file "c:\python27\lib\subprocess.py", line 672, in __init__

errread, errwrite)

file "c:\python27\lib\subprocess.py", line 882, in _execute_child

startupinfo)

windowserror: [error 2] 

windowsxp安裝版本

低版本作業系統安裝

掃瞄主機埠**

print('主機名稱:()'.format(host,nm[host].hostname()))

print('主機狀態:'.format(nm[host].state()))

'''主機名稱:14.215.177.38(www.baidu.com)

主機狀態:up

'''for proto in nm[host].all_protocols():

print('協議:'.format(proto))

lport=list(nm[host][proto].keys())

lport.sort()

for port in lport:

print('埠: 詳情:'.format(port,nm[host][proto][port]))

'''協議:tcp

埠:80 詳情:

埠:443 詳情:

'''#掃瞄出ip位址開放了哪些埠

nm1=nmap.portscanner()

ip='10.20.30.40'

nm1.scan(ip,'1-1024')

for p in nm1[ip].all_protocols():

print('開放的埠:'.format([port for port in nm1[ip][p].keys()]))

#把乙個網段裡開放855埠的ip位址給找出來

def findip(subnet):

nm = nmap.portscanner()

nm.scan(subnet, '855')

ips =

for host in nm.all_hosts():

if nm[host].has_tcp(855):

state = nm[host]['tcp'][855]['state']

if state == 'open':

return ips

print(findip('10.20.30.0/24'))

nmap 配合brutespray進行爆破

在使用了nmap獲取了目標伺服器的資訊之後,可以使用nmap自帶的指令碼進行爆破,但是不夠方便。這裡介紹開源專案brutespray,利用medusa和nmap掃瞄結果進行爆破。使用brutespray的好處是,首先是可以批量,其次是支援多種協議。流程非常簡單 nmap進行掃瞄,必須帶上 sv引數來...

python使用nmap埠掃瞄

coding utf 8 usr bin env python import nmap import optparse def nmapscan tgthost,tgtport 建立nmap掃瞄器,初始化portscanner模組 class portscanner init self,nmap s...

nmap使用小結

更細節的知識請看nmap的manpage,這裡主要是解釋nmap的乙個gtk前端zenmap中的預設幾個掃瞄命令的選項 intense scan nmap t4 a v www.rickyzhang.me t 0 5 set timing template higher is faster a en...