python最大的特点就是各种强大的模块实现自己想要的功能。这里介绍一个强大的工具––nmap。
windows环境下要先安装nmap,地址
https://nmap.org/download.html,安装 nmap-7.80-setup.exe,下面会用到。然后pip install nmap安装python模块。利用tkinter实现图形化界面。功能实现程序:
<code>import
tkinteras
tkimport
nmap topwin = tk.Tk() topwin.title("ipScanV1.0"
) topwin.geometry("400x200+20+20"
) topwin.attributes("-alpha"
,1
) topwin["bg"
] ="snow"
topwin.resizable(False
,False
) infotext = tk.Text(topwin,bg ="Turquoise"
) scrobar = tk.Scrollbar(infotext) scrobar.pack(side="right"
, fill="y"
) scrobar.config(command=infotext.yview) infotext.config(yscrollcommand=scrobar.set) infotext.tag_configure('color'
, foreground='Yellow'
,background ="RoyalBlue"
) infotext.place(x=4
,y=40
,width =400
,height =160
) ipscanset = tk.Label(topwin,text ="输入扫描IP段:"
).place(x=10
,y=10
) iptext = tk.Entry(topwin) iptext.place(x=100
,y=10
,width =140
,height =24
,anchor ="nw"
)def
ipscan
()
: ipyn = nmap.PortScanner(nmap_search_path=('nmap'
,r'C:\Program Files\Nmap\nmap.exe'
)) ip = iptext.get()if
len(ip) ==0
: infotext.insert(tk.END,"请输入正确IP或IP段!\n"
) infotext.insert(tk.END,"...............................\n"
)else
: ping_scan = ipyn.scan(hosts=ip,arguments="-sn"
) infotext.insert(tk.END,"...............................\n"
)if
len(ping_scan['scan'
]) ==0
: infotext.insert(tk.END,"%s该网段无设备在线!\r\n"
%(ip))else
:for
resultin
ping_scan['scan'
].keys(): infotext.insert(tk.END,"%s 设备在线!\r\n"
%(result)) scanbtn = tk.Button(topwin,text ="扫描"
,command = ipscan).place(x=250
,y=10
,width =50
,height =24
) topwin.mainloop() /<code>
注意:nmap.PortScanner(nmap_search_path=('nmap',r'C:\Program Files\Nmap\nmap.exe'))一定要按照自己安装的路径添加,否则报错。
软件实现效果如下图所示: