I'm trying to run WifiPhisher for educational purposes. At one step it says Press Ctrl-C to input a number. Now when I press Ctrl-c the script exits as I described it in this issue on github. Whereas ideally, the script shouldn't exit rather it should continue the logic after Ctrl-C is pressed. I'm not familiar with Python, can anyone help me get past this?
Python allows us to set up signal -handlers so when a particular signal arrives to our program we can have a behavior different from the default. For example when you run a program on the terminal and press Ctrl-C the default behavior is to quit the program.
It's because of the design of the Python interpreter and interactive session. Ctrl + C sends a signal, SIGINT, to the Python process, which the Python interpreter handles by raising the KeyboardInterrupt exception in the currently-running scope.
To stop code execution in Python you first need to import the sys object. After this you can then call the exit() method to stop the program running. It is the most reliable, cross-platform way of stopping code execution.
You can set a signal handler
to CTRL-C
signal to shutdown the default signal handler
which raises a KeyboardInterrupt
exception.
import signal, os
def handler(signum, frame):
print 'Signal handler called with signal', signum
# Set the signal handler
signal.signal(signal.SIGINT, handler)
Ctrl-C (in older Unixes, DEL) sends an INT signal (SIGINT); by default, this causes the process to terminate
SIGINT The SIGINT signal is sent to a process by its controlling terminal when a user wishes to interrupt the process. This is typically initiated by pressing Control-C, but on some systems, the "delete" character or "break" key can be used.[6]
https://docs.python.org/2/library/signal.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With