Skip to content

Instantly share code, notes, and snippets.

@dweinstein
Last active December 31, 2015 18:39
Show Gist options
  • Select an option

  • Save dweinstein/8028634 to your computer and use it in GitHub Desktop.

Select an option

Save dweinstein/8028634 to your computer and use it in GitHub Desktop.
#!/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