首页 > 代码库 > 01-扫描-使用nmap端口扫描
01-扫描-使用nmap端口扫描
Python 2.7.12+ (default, Sep 1 2016, 20:27:38)
[GCC 6.2.0 20160822] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import nmap import optparse def nmapScan(tgtHost,tgtPort): nmScan = nmap.PortScanner() nmScan.scan(tgtHost,tgtPort) state=nmScan[tgtHost][‘tcp‘][int(tgtPort)][‘state‘] print "[*] " + tgtHost + " tcp/"+tgtPort +" "+state def main(): parser = optparse.OptionParser(‘usage %prog ‘+ ‘-H <target host> -p <target port>‘) parser.add_option(‘-H‘, dest=‘tgtHost‘, type=‘string‘, help=‘specify target host‘) parser.add_option(‘-p‘, dest=‘tgtPort‘, type=‘string‘, help=‘specify target port[s] separated by comma‘) (options, args) = parser.parse_args() tgtHost = options.tgtHost tgtPorts = str(options.tgtPort).split(‘,‘) if (tgtHost == None) | (tgtPorts[0] == None): print parser.usage exit(0) for tgtPort in tgtPorts: nmapScan(tgtHost, tgtPort) if __name__ == ‘__main__‘: main()
本文出自 “文东会” 博客,请务必保留此出处http://hackerwang.blog.51cto.com/734458/1906804
01-扫描-使用nmap端口扫描
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。