输出显示不正确

时间:2019-06-13 07:33:38

标签: python python-3.x nmap

使用nmap参数运行Python3时,输出仅显示为-1

try:
    import os, sys, time
except:
    sys.exit("[!] Install 'os, sys, time' modules: pip3 install os -|- check whether 'Nmap' is installed: https://nmap.org/")


class recon_scanner():

    def nMap(self):
        tgtHost = input("Enter the target: ")
        tgtPort = input("Enter the target port: ") 

        options = input("""\n Please choose an option:
           [1] TCP NULL|sN|+|Pn|+|sV|+|sC|+|O|+|version-intensity 9|+|reason|
           [2] TCP FIN|sF|+|Pn|+|sV|+|sC|+|O|+|version-intensity 9|+|reason|
           [3] TCP XMAS|sX|+|Pn|+|sV|+|sC|+|O|+|version-intensity 9|+|reason| \n""")

        print("You have selected option: ",options, '\n')

        if options == '1':
            scanner1 = os.system("nmap -Pn -sN -A -v --version-intensity 9 --reason" + str(tgtHost) + str(tgtPort))
            print(scanner1)

scan_result = recon_scanner()
scan_result.nMap()

1 个答案:

答案 0 :(得分:1)

尝试使用os.popen而不是os.system,以字符串形式获取输出:

scanner1 = os.popen("nmap -Pn -sN -A -v --version-intensity 9 --reason" + str(tgtHost) + str(tgtPort)).read()

然后您可以像打印其他任何字符串一样打印