简体   繁体   中英

How to call nikto from python and return output as a string

This function should call nikto an return it's output as a string but instead just hangs forever. I'm desperate to figure out why this is not working and i have tried everything i could think of.

def nikto(host, *args):
    arguments = ' '.join(args)
    command = 'nikto -host {} {}'.format(host, arguments)
    return commands.getoutput(command)

What is nikto?

Nikto is an Open Source (GPL) web server scanner which performs comprehensive tests against web servers for multiple items, including over 6400 potentially dangerous files/CGIs, checks for outdated versions of over 1200 servers, and version specific problems on over 270 servers.

What language is Nikto written in?

Perl

Note:

I have also tried os.popen('nikto').read()

My system

Linux rwilson-Aspire-E5-521 3.16.0-55-generic #74~14.04.1-Ubuntu SMP Tue Nov 17 10:15:59 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

If you want to call command and get its output simpy use subprocess.check_output .

def nikto(host, *args):
    return subprocess.check_output(['nikto', '-host', host] + args)

Note, however, that this method will raise an exception if the return code of your command is non-zero, but the exception will contain the output in its output attribute.

If you want to capture both stderr and stdout of your command add the argument stderr=subprocess.STDOUT .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM