Using Android phone as wifi web server

二次信任 提交于 2019-12-07 05:36:07

问题


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.


回答1:


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.




回答2:


Like has been said, you'll need IPTables, but you'll also need a proxy server, like Squid.

Google "transparent proxy with squid", or check here:
Linux: Setup a transparent proxy with Squid in three easy steps




回答3:


you do not need to have a proxy, you just need a full LAMP stack on your device and IPtables, you can mark all packets that have not been authenticated to forward through to your local page, then using php change the rule for that IP address once the address has authenticated, you could do the same for mac addresses if you wish, you would then also need a daemon that periodically reset each exception



来源:https://stackoverflow.com/questions/5353911/using-android-phone-as-wifi-web-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!