zoukankan      html  css  js  c++  java
  • Python2之nmap扫描端口与服务开启情况和服务扫描和扫描目标系统

    题记

           元旦看电影的时候发现自己在微信抽中了一台kali服务器,真是需要什么来什么,有时候觉得自己是一个不坚定的唯物主义者,总在特定的时候看到特定的事。接下来一个月我要把持住这个机会,把自己的想法的实现了。

    nmap扫描端口与服务开启情况

    import sys

    import nmap

    if len(sys.argv) != 3 :

        print ("usage:PortScanner eg:192.168.0.1 80-554")

        sys.exit(1)

    target=sys.argv[1]

    port=sys.argv[2]

    nm=nmap.PortScanner()

    nm.scan(target,port)

    for host in nm.all_hosts():

        print("----------------------------------------------")

        print('host:{0}({1})'.format(host,nm[host].hostname()))

        print("state:{0}".format(nm[host].state()))

        for proto in nm[host].all_protocols():

            print ("-----------------------------")

            print("proto:{0}".format(proto))

            lport=list(nm[host][proto].keys()) #获取协议的所有扫描端口

            lport.sort()

            for port in lport:

                print("port:{0} state:{1}".format(port,nm[host][proto][port]))

    服务扫描

    import sys

    import nmap

    if len(sys.argv) != 3 :

        print ("usage:ServiceScan eg:192.168.0.1 80-554")

        sys.exit(1)

    target=sys.argv[1]

    port=sys.argv[2]

    nm=nmap.PortScanner()

    nm.scan(target,port,"-sV")

    for host in nm.all_hosts():

        for proto in nm[host].all_protocols():

            lport=list(nm[host][proto].keys())

            lport.sort()

            for port in lport:

                print("port:{0} product:{1}".format(port,nm[host][proto][port]['product']))

    目标系统扫描

    import sys

    import nmap

    if len(sys.argv) != 2:

        print('usage:osscan eg:192.168.0.1 ')

        sys.exit(1)

    target=sys.argv[1]

    nm=nmap.PortScanner()

    nm.scan(target,arguments="-O")

    if 'osmatch' in nm[target]:

        for osmatch in nm[target]['osmatch']:

            print ('Osmatch.name: {0}'.format(osmatch['name']))

            print ('Osmatch.accuracy: {0}'.format(osmatch['accuracy']))

            print ('Osmatch.line: {0}'.format(osmatch['line']))

            print ('')

            if 'osclass' in osmatch:

                for osclass in osmatch['osclass']:

                    print ('Osclass.type: {0}'.format(osclass['type']))

                    print ('Osclass.vendor: {0}'.format(osclass['vendor']))

                    print ('Osclass.osfamily: {0}'.format(osclass['osfamily']))

                    print ('Osclass.osgen: {0}'.format(osclass['osgen']))

                    print ('Osclass.accuracy: {0}'.format(osclass['accuracy']))

                    print ('')

  • 相关阅读:
    DirectX:在graph自己主动连线中增加自己定义filter(graph中遍历filter)
    C3P0数据库连接池使用
    POJ
    【jQuery】复选框的全选、反选,推断哪些复选框被选中
    BestCoder Round #75 King's Cake 模拟&&优化 || gcd
    《Javascript_Dom 编程艺术》(第2版)读书笔记
    POJ 2947-Widget Factory(高斯消元解同余方程式)
    MFC 小知识总结四
    迭代器和iter()函数
    hdu1595find the longest of the shortest 最短路
  • 原文地址:https://www.cnblogs.com/sunny11/p/14226954.html
Copyright © 2011-2022 走看看