If you are like me and do a lot of work on different devices and need to debug what is going on this little trick can be invaluable. This only takes 3 mins to setup and is invaluable.
Tools you will need:
- An OS X based machine (as all good multi device developers should have, could also be done on linux)
- A device
- A Copy of Charles Proxy (also an essential tools for developers – http://www.charlesproxy.com/
- A wifi or fixed network with both devices on the network
What we are going to do is setup the OS X machine to be a router and forward any traffic that is on port 80 and 443 to the Charles Proxy and make sure that Charles has transparent proxy mode enabled. Note that without the SSL certs installed on the devices for the proxy you may need to drop the 443 forwarding.
- Enable IP forwarding:
sudo sysctl -w net.inet.ip.forwarding=1
- Place the following two lines in a file called, say, pf.conf:
rdr on en2 inet proto tcp to any port 80 -> 127.0.0.1 port 8080 rdr on en2 inet proto tcp to any port 443 -> 127.0.0.1 port 8080
These rules tell pf to redirect all traffic destined for port 80 or 443 to the local mitmproxy instance running on port 8080. You should replace en2 with the interface on which your test device will appear.
- Configure pf with the rules:
sudo pfctl -f pf.conf
- And now enable it:
sudo pfctl -e
Note I borrowed this form mitmproxy proxy which I will definitely be trying out as sounds like my kind of proxy even though Charles is handy for the formatted JSON/XML views: mitmproxy
Now you need to configure only the default gateway of your device to point at the interface on your OS X machine. Note that on my Macbook using wifi that looks like this:
>ifconfig en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1453 ether 20:c9:d0:49:98:31 inet6 fe80::22c9:d0ff:fe49:9831%en0 prefixlen 64 scopeid 0x4 inet 10.33.195.97 netmask 0xffffffc0 broadcast 10.33.195.127 nd6 options=1<PERFORMNUD> media: autoselect status: active
The last bit is you need to set Charles in Transparent Proxy mode:
And then with some luck like I had it all works first time and I now have an LG TV that doesn’t support proxy settings working through my proxy in <5 mins without any special hardware.