1

The output of results from a netdiscover scan does not post to the webpage. I assume this is because the program doesn't wait until the bash command has finished executing before posting results using Python CGI. I have tried the .sleep function to wait until the process has finished executing, this didn't work. The users IP address does post to the webpage from the ifconfig command, however netdiscover does not on the line: print("%s - %s" % (i + 1, ip)) The code runs fine in a Kali Terminal as shown: terminal output The web output: Web output

def bash(command):
    return subprocess.check_output(['bash', '-c', command])


def nmap_scan(ip):
    print(("<H1>Scanning TCP ports on %s</H1>" % ip))
    res = bash('nmap -T4 -p1-65535 %s | grep "open"' % ip).splitlines()
    ports = []

    for port in res:
        print(port)
        ports.append(port.split("/")[0])

    port_list = ",".join(ports)
    print("<H1>\nRunning intense scan on open ports...\n</H1>")
    bash('nmap -T4 -A -sV -p%s -oN output.txt %s' % (port_list, ip))
    print("</H1>Nmap intense scan  results logged in 'output.txt'</H1>")
    exit()

ip_string = bash('ifconfig eth0 | grep "inet "')

ip = ip_string.decode("utf-8").strip().split(" ")[1]

print(("<H1>Your IP Address is: </H1>" + ip + "\n"))

octets = ".".join(ip.split(".")[:-1])
subnet = octets + ".0/24"
print(("<H1>Running netdiscover on local subnet: %s</H1>" % subnet))

ips = bash('netdiscover -P -r %s | grep "1" | cut -d " " -f2 ' % subnet).splitlines()

print("<H4>%s - %s</H4>" % (i + 1, ip))



choice = input("<H1>\nEnter an option 1 - %s, or 0 to exit the script:\n</H1>" % len(ips))
nmap_scan(ips[choice - 1])

0 Answers0