Created
June 16, 2023 18:23
-
-
Save Lucho00Cuba/76caaff27da773ea8759731522eef8d8 to your computer and use it in GitHub Desktop.
Socat Control
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SOCKS_PID_FILE="/tmp/socat.pid" | |
start_socat() { | |
socat TCP4-LISTEN:1080,fork SOCKS4A:localhost:www.example.com:80,socksport=1080 & | |
echo $! > "$SOCKS_PID_FILE" | |
echo "socat started with PID $!" | |
} | |
stop_socat() { | |
if [[ -f "$SOCKS_PID_FILE" ]]; then | |
pid=$(cat "$SOCKS_PID_FILE") | |
kill "$pid" | |
rm "$SOCKS_PID_FILE" | |
echo "socat stopped (PID $pid)" | |
else | |
echo "socat is not running" | |
fi | |
} | |
status_socat() { | |
if [[ -f "$SOCKS_PID_FILE" ]]; then | |
pid=$(cat "$SOCKS_PID_FILE") | |
if ps -p "$pid" > /dev/null; then | |
echo "socat is running (PID $pid)" | |
else | |
echo "socat is not running" | |
rm "$SOCKS_PID_FILE" | |
fi | |
else | |
echo "socat is not running" | |
fi | |
} | |
case "$1" in | |
start) | |
start_socat | |
;; | |
stop) | |
stop_socat | |
;; | |
status) | |
status_socat | |
;; | |
*) | |
echo "Usage: $0 {start|stop|status}" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment