2

enter image description hereI want to use subprocess.popen and excute airodump --bssid xxxx:xxxx:xxxx:xxxx - c xxx:xxxx:xxx:xxxx -w tmp.ivs, but it has a console window, I want to hide it.

for ap in aps:
    args = "airodump-ng --bssid {BSSID} -c {CH} --output-format netxml -w {name}.ivs wlan0mon".format(
        BSSID=ap.get("BSSID"),
        CH=ap.get(' channel'),
        name=ap.get("BSSID"))
    print(args)
    p=multiprocessing.Process(subprocess.Popen,args=(args.split(),))
    p.start()
    p.join()

When I run this code on kali, all the console windows come out, so I want to hide all the windows. I searched for a long time and still got no idea how to do it, so thanks if you help me.

胡永雷
  • 31
  • 5
  • pyw extension rather than .py? – Xantium Jul 05 '18 at 16:17
  • just py file, not pyw extension – 胡永雷 Jul 05 '18 at 16:22
  • did i make it clear? my english is not good ,so if something not clear,just ask,thanks – 胡永雷 Jul 05 '18 at 16:49
  • You seem clear enough. I think it was me who was unclear ;) What i meant was that you can hide the console window by changing it to pyw https://stackoverflow.com/questions/764631/how-to-hide-console-window-in-python – Xantium Jul 05 '18 at 16:51
  • 1
    @Simon, the `.pyw` convention is a Windows thing. Kali is a Linux distribution -- running a program that doesn't perform explicit GUI interaction doesn't open a window on Linux in the first place, so this question makes no sense. – Charles Duffy Jul 05 '18 at 16:57
  • @胡永雷, ...btw, in general, `args.split()` is a very unfortunate habit to be in -- it'll break badly if you ever have a BSSID or an output filename with spaces, for example. Much better to specify an explicit array: `args=[ 'airodump-ng', '--bssid', str(ap.get("BSSID")), '-c', str(ap.get(' channel'))', ...]`. If maliciously-formed arguments to `airodump-ng` can cause arbitrary commands to be run, using `args.split()` may even be a security risk. – Charles Duffy Jul 05 '18 at 16:59
  • (...also, Kali is a Linux distro focused on some very specialized domains and [not recommended for general-purpose use](https://unix.stackexchange.com/questions/399626/why-is-kali-linux-so-hard-to-set-up-why-wont-people-help-me), but that's neither here nor there). – Charles Duffy Jul 05 '18 at 17:01
  • inneed kali is a Linux distribution – 胡永雷 Jul 05 '18 at 17:03
  • thanks,i will change the code,I will accept your proposal, I just want to improve my programming skills – 胡永雷 Jul 05 '18 at 17:11

1 Answers1

0
import multiprocessing
import subprocess

def executeCommand(exeArgs, output):
    commandProcess = subprocess.Popen(exeArgs.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out, err = commandProcess.communicate()

    output.put(out)

command = "Your command Here"
output = multiprocessing.Queue()
p = multiprocessing.Process(target=executeCommand, args=(command, output) )
p.start()
p.join()
#print output.get()

As you can see the last line is commented. That way I don't show anything in the terminal, but if you want to print it you always can uncomment it.

I think that is what you want.

Ricardo
  • 1,308
  • 1
  • 10
  • 21
  • The code output = multiprocessing.Queue() means what?,As i add this before calling multiprocess.Process , Nothing happens,Can you explain what the code to do ? – 胡永雷 Jul 07 '18 at 06:28
  • whit the multiprocessing.Queue() i can store easily any object of python, in this case i just use it to get the output. – Ricardo Jul 08 '18 at 05:33
  • Yeah,This is what I want, Thank you very much! god bless you ~ ,uhhh – 胡永雷 Jul 08 '18 at 15:38