一、工具说明
调用nmap库实现端口扫描
二、演示一下的利用效果
三、代码+注释
import nmap import argparse def nmapScan(Host, Port): # 调用nmap的PortScanner类 nm = nmap.PortScanner() # 使用scan方法进行扫描 results = nm.scan(Host, str(Port)) state = results[‘scan‘][Host][‘tcp‘][Port][‘state‘] print("[+] {} tcp/{} {}".format(Host, Port, state)) def main(): parser = argparse.ArgumentParser() parser.add_argument(‘-H‘, dest=‘Host‘, help="Host like: 192.168.3.1") parser.add_argument(‘-p‘, dest=‘Ports‘, nargs=‘+‘, type=int, help="Port like: 80 443 21") args = parser.parse_args() Host = args.Host Ports = args.Ports for Port in Ports: nmapScan(Host,Port) if __name__ == ‘__main__‘: main()
时间: 2024-10-06 05:31:30