I have a webserver that is running on a network that is not connected to the internet.
The webserver serves up a website.
When I connect an android phone to it, I am able to run the website that is on the webserver
But with certain phones that are running Android 11 I need to disable the mobile data on the phone before it will try to access the website over wifi. It seems the phone will not try to request the url on the wifi network because it doesn't have internet, so it defaults to using the 4G/5G Cellular internet connection. This is too bad, because I would like the phone to use the wifi connection.
I would think that perhaops I could "force" the phone to use the wifi connection by typing the IP address in the browser's URL bar (eg. http://192.168.211.1/index.php), however it seems that even with the "local ip" it will still try to use the 4G/5G network instead of the "offline wifi" network.
The only workaround I have found is to disable moblie data on the phone, but this is not ideal.
I would think that some IoT devices would have an offline webserver used for configuation/control.
Is there a certain port or settings I should be using?
Is there a designated port that the browser/OS would expect to be on an offline network?
Basically, how can I make the phone use the wifi, even though the wifi is not connected to the internet?
Thanks so much for any pointers!
I am implementing captive portal for a local WiFi network (the hotspot where device needs to 'authenticate' before it's traffic can be fully routed to the Internet).
When Android devices detects captivity it is able to show login page from the default gateway web server # 192.168.88.1.
However when I try to connect to other host in the same network e.g. 192.168.88.123 Android refuses to do so even though other devices (notebooks) have no problem with that.
Can this be solved somehow or is this a way Android works for some (security) reason ?
I am writing an app which I want to connect to a closed (no internet access) bluetooth PAN to access a local data server. When connecting to the PAN I want the user to still have internet access via their existing 4G/WiFi data connection.
I have set up DNSMasq on the PAN gateway and have configured the dns options to not provide a gateway/DNS server for the interface.
Using reflection I can connect a phone to the PAN but the phone then drops any other network connections.
With the new Android api's (NetworkBuilder & ConnectivityManager.requestNetwork) I can request a WiFi connection before connecting to the PAN and the phone will keep both connections up. The problem is that other apps on the phone still do not have internet access. It would appear that the device is adding a default route for the bt-pan interface, even though dhcp has not provided a router option (confirmed via Wireshark).
Is it possible to connect to a network without setting a default gateway so other apps will continue to use 4G/WiFi interface?
Is it possible to dedicate a WiFi network (to a device with no internet access) to a socket in an app and keep Cellular network as the default internet connection for the Android device (and other network requests from the app)? (Android 5 & 6)
I can easily switch between WiFi and Cellular within the app but the main issue is when WiFi is up, Internet is not accessible anymore for the app and all apps already running on the device (i.e. streaming music, web browser, ...)
I have tried to bind the Wifi network to the process or a socket but I can't find any way to do that with getting the network active (and at this point Android just try to route all the internet traffic to the device...).
My understanding is that Android 5 & 6 provides more flexibility to route traffic to multiple networks at the same time but I think I'm missing something here...
As per the Connecting your App to a Wi-Fi Device blog post:
Alternatively, if you’d like to route some of your app traffic to the Wi-Fi device and some to the Internet over the mobile network:
For HTTP requests you can use Network#openConnection(java.net.URL), directly routing your request to this network.
For low-level socket communication, open a socket and call Network#bindSocket(java.net.Socket), or alternatively use Network#getSocketFactory.
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.
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
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