Last active
December 31, 2015 18:39
-
-
Save dweinstein/8028634 to your computer and use it in GitHub Desktop.
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/sh | |
| PROXY_HOST=$(ifconfig en0 | grep "inet " | awk '{print $2}') | |
| PROXY_PORT=8080 | |
| function adb_shell { | |
| cmd="$1" | |
| adb shell "${cmd}" | |
| } | |
| function sh_sudo { | |
| cmd="$1" | |
| adb_shell "/system/bin/su -c \"${cmd}\"" | |
| } | |
| function enable_forward { | |
| sh_sudo "echo 1 > /proc/sys/net/ipv4/ip_forward" | |
| } | |
| function disable_forward { | |
| sh_sudo "echo 0 > /proc/sys/net/ipv4/ip_forward" | |
| } | |
| function redirect_port { | |
| dport=$1 | |
| proxy_host=$2 | |
| proxy_port=$3 | |
| sh_sudo "iptables -t nat -A PREROUTING -p tcp --dport ${dport} -j DNAT --to-destination ${proxy_host}:${proxy_port}" | |
| } | |
| function iptable_flush { | |
| sh_sudo "iptables --flush" | |
| } | |
| # test | |
| iptable_flush | |
| enable_forward | |
| redirect_port 80 ${PROXY_HOST} ${PROXY_PORT} | |
| redirect_port 443 ${PROXY_HOST} ${PROXY_PORT} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment