Created
September 3, 2014 14:52
Revisions
-
sirupsen created this gist
Sep 3, 2014 .There are no files selected for viewing
This file contains 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ #!/bin/bash if [[ -z $1 ]]; then echo -e "\x1b[31mMust supply src + dest port" exit 1 fi echo -e "\x1b[32mForwarded port $2 --> $1\x1b[33m" sudo iptables -t nat -I OUTPUT -p tcp -o lo --dport $2 -j REDIRECT --to-ports $1 read -e -p "Hit enter to kill port redirect.." echo "Killing iptables forward.." sudo iptables -t nat -D OUTPUT 1 PID=$(ps aux | grep -i [r]ails | awk '{print $2}') FD=$(sudo lsof -p $PID | grep $2 | awk '{print $4}') if [[ -z $FD ]]; then echo -e "\x1b[31mNo FD found" exit 1 fi echo "p close($FD)" | sudo gdb -p $PID