简单的扫描工具

import nmap
import argparse

def get_parameter():
    parser=argparse.ArgumentParser(description='该脚本用于探查主机存活情况')
    parser.add_argument('-n',dest='networkPrefix',type=str,default='',help='输入待探测主机网段范围')
    parser.add_argument('-s',dest='status',type=str,default='up',help='选择打印的主机状态,默认为UP')
    args=parser.parse_args()
    networkPrefix=args.networkPrefix
    status=args.status.lower()
    return networkPrefix,status

def nmap_ping_scan(networkPrefix):
    nm=nmap.PortScanner()
    result=nm.scan(hosts=networkPrefix,arguments='-v -n -sn')
    return result

def main():
    networkPrefix,status=get_parameter()
    result=nmap_ping_scan(networkPrefix)
    for clientIP,clientInfo in result['scan'].items():
        clientStatus=clientInfo['status']['state']
        if status==clientStatus:
            print('{:<15} is {}'.format(clientIP,clientStatus))


if __name__=='__main__':
    main()

  

posted @ 2020-04-26 22:45  魔阳工  阅读(135)  评论(0编辑  收藏  举报