I got this crazy idea that I don’t know is possible or not… what I want to do is set up my phone as wifi access point, then allow people to connect to it, but handle all incoming http traffic myself.
So:
-
phone wifi in access point mode; open wifi network (this tidbit works – yes I know it’s not officially supported but then I have no intention to distribute put this app on the open market or so, it works on my phone and that’s good enough for me).
-
client can connect to the phone (e.g. my laptop: this also works).
-
when client tries to open an http connection to any random server, this has to be intercepted by my app and handled by a local web server. This is the point that I’m stuck on.
The web server part shouldn’t be too hard; there are (open-source) web servers available. But getting the traffic to that web server, there is the problem.
The behaviour I’m after is a bit similar to what you get when connecting to some open hotspot, like hotel hotspots, that then redirect you to a login page. This intercepting of the connection request (I suspect I have to look at DNS requests?) is what I’m after.
I have seen an app that is doing this but they require the phone to be rooted. I’m hoping to find a way to do it without rooting the phone.
Wifi hotspots would usually use IPTables to redirect port 80/443 traffic to a local web server.
I have run squid on linux machines in the past on port 3128, then sent all port 80/443 traffic to squid. Then I used squid redirect any url that I didnt explicitly allow to a local web server.
IPTables is accessible on rooted android devices only though.
And I doubt there are many proxy servers available on android, so you would have to send HTTP traffic to a proxy server over the network connection.