Skip to content

Instantly share code, notes, and snippets.

@dweinstein
Created November 19, 2014 18:42
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dweinstein/56fb8c41060a1de580e3 to your computer and use it in GitHub Desktop.
Save dweinstein/56fb8c41060a1de580e3 to your computer and use it in GitHub Desktop.
iptable adb android
#!/bin/sh
set -x
PROXY_HOST=$(ifconfig en0 | grep "inet " | awk '{print $2}')
PROXY_PORT=8080
function adb_shell {
local cmd="$1"
adb shell "${cmd}"
}
function sh_sudo {
local 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 {
local dport=$1
local proxy=$2:$3
sh_sudo "iptables -t nat -A PREROUTING -p tcp --dport ${dport} -j DNAT --to-destination $proxy"
}
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