使用nmap扫描端口

发布时间 2023-04-23 17:49:45作者: 细水流深-LHF的博客


import nmap

scanner = nmap.PortScanner()

target = '192.168.8.121'

scanner.scan(target, arguments='-p-')

for host in scanner.all_hosts():
    print(host)
    if scanner[host].state() == 'up':
        print('Host: %s (%s)' % (host, scanner[host].hostname()))
        print('State: %s' % scanner[host].state())
        for proto in scanner[host].all_protocols():
            print('----------')
            print('Protocol: %s' % proto)
            lport = scanner[host][proto].keys()
            for port in lport:
                print ('Port : %s\tState : %s' % (port, scanner[host][proto][port]['state']))