Example #1
0
def nmap_scan(target, commands):
    nm = NmapProcess(target, commands)
    #change to sudo_run(run_as='root') to run syn scans
    nm.run_background()
    command = nm.get_command_line()
    print(command)
    while nm.is_running():
        print("Nmap Scan running: ETC: {0} DONE: {1}%".format(
            nm.etc, nm.progress))
        sleep(1)
    nmap_report = NmapParser.parse(nm.stdout)
    for host in nmap_report.hosts:

        if host.status == 'up':
            for serv in host.services:
                # if serv.port == 'open':
                service_check(host, serv)
    print("Primary Scan Completed \n")
Example #2
0
def nmap_service_scan(host, service, command):
    port = service.port
    nm = NmapProcess(host.address, options=command + " -p " + str(port))
    # change to sudo_run(run_as='root') to run syn scans
    nm.run_background()
    command = nm.get_command_line()
    print(command)
    while nm.is_running():
        print("Nmap Service Scan running:" + host.address + " : " +
              str(service.port) +
              " ETC: {0} DONE: {1}%".format(nm.etc, nm.progress))
        sleep(10)
    nmap_report = NmapParser.parse(nm.stdout)
    for host_service in nmap_report.hosts:
        for serv in host_service.services:
            pserv = "{0:>5s}/{1:3s}  {2:12s}  {3} ".format(
                str(serv.port), host.address, serv.protocol, serv.state,
                serv.service)
            print(pserv)
            for result in serv.scripts_results:
                print(result["output"])
            print("\n")
from libnmap.process import NmapProcess

nmap_proc = NmapProcess(targets="192.168.1.0/24", options="-sP")
print nmap_proc.get_command_line()
nmap_proc.run()
print nmap_proc.summary
print nmap_proc.targets