使用nmap扫描端口


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']))

posted @ 2023-04-23 17:44  公众号海哥python  阅读(46)  评论(0编辑  收藏  举报