0

I am completely new to the subprocess module. And I was trying to automate the deauthentication attack commands. When I run airodump-ng wlan0mon as you know it looks for the APs nearby and the connected clients to it.

Now when I try to run this command using lets suppose p = subprocess.run(["airmon-ng","wlan0mon"], capture_output=True) in Python as you know this command runs until the user hits Ctrl+C, so it should save the last output when user hits Ctrl+C in the variable but instead I get error which is this:

Traceback (most recent call last):
  File "Deauth.py", line 9, in <module>
    p3 = subprocess.run(["airodump-ng","wlan0"], capture_output=True)
  File "/usr/lib/python3.8/subprocess.py", line 491, in run
    stdout, stderr = process.communicate(input, timeout=timeout)
  File "/usr/lib/python3.8/subprocess.py", line 1024, in communicate
    stdout, stderr = self._communicate(input, endtime, timeout)
  File "/usr/lib/python3.8/subprocess.py", line 1866, in _communicate
    ready = selector.select(timeout)
  File "/usr/lib/python3.8/selectors.py", line 415, in select
    fd_event_list = self._selector.poll(timeout)
KeyboardInterrupt

What can I try to resolve this?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Sep 23 '20 at 19:05
  • 1
    I am sorry. I'll avoid it next time. Thanks for editing my question. – Sarib Ali Virk Sep 24 '20 at 11:32

1 Answers1

0

Just use Python's error handling. Catch any KeyboardInnterrupts (within your subprocess function) using try and except statements like so:

def stuff(things):
  try:
    # do stuff
  except KeyboardInterrupt:
    return last_value
JaonHax
  • 336
  • 1
  • 8
  • Would you explain it a little bit more because I don't understand it. May be you can write it for the command I provided in my question. By the way thanks for the answer. – Sarib Ali Virk Sep 24 '20 at 11:37