I have an Android tablet with a USB to ethernet adapter. The network interface is configured and the default gateway works and allow internet access.
To fix an issue we are having I would like to change the default gateway to something that is incorrect which will cause the tablet to not be able to access the internet.
Then in our Xamarin application I would like to route the internet traffic through the USB to ethernet NIC like normal but I want to programmatically specify the correct gateway somehow without changing the gateway on the NIC. I can also remove the gateway altogether if that would do the same thing and block traffic. But in that case do I have to do anything special in the traffic to send the traffic to the 192.168.1.1 gateway?
Is this technically possible at all in Xamarin or Java/Android? I am also open to somehow configuring Android itself so that only our application has a valid routing table but I am not sure how to do that.
Thanks ahead of time!
I have not tried anything yet to fix this I'm just brainstorming issues.
The document is about WiFiManager. There is a method. But this method was deprecated in API level 29.
At present, the successful changes are all in Android 6.0 and earlier.
Here are two links you can refer to them:
How to configure a static IP address, netmask, gateway programmatically on Android 3.x or 4.x
Set static IP and gateway programmatically in Android 6.x (Marshmallow).
Related
I am trying to establish tcp/ip connection over bluetooth,currently android bluetooth api provides support only for headset,a2dp and health device profiles,but I need PAN profile on manually assigned Ip address,I am not sure but I read somewhere even if you connect your phone to laptop using pan profile the ip address is automatically assigned,and you need to root your phone to manually assign them.Is it possible?
Is it possible to do easily over other platforms like ios or windows phone?
You can use Pan profile in Android, however It is not officially supported. Take a look at the Android Internal API.
I'm working on some test project, basically I want to route all traffic when I'm in hotspot mode into a fixed address. I have the IP range for example 192.168.0.0/24 I don't know if I can use iptables without root or JNI functions (can't find any that match what I want)
Thinking out of the box is very welcomed (DNS, low level packet broadcast on client connect etc...)
Any Idea?
EDIT: How Android and iOS detect a Network Portal?
source : https://sudoroom.org/wiki/Mesh/Firmware/Splash_page
They try to HTTP GET on
iOS: http://www.apple.com/library/test/success.html and expect a 200 if not behind portal
Android: http://clients3.google.com/generate_204 and expect a 204 status when not behind portal, any other status is a portal
So, how can I respond correctly to those detections?
The easiest approach is to enable a socks proxy when configuring the wifi AP you are connecting to. This varies depending on the version of android, but it is typically something like:
Touch and hold the wifi network you want to connect to.
A dialogue box should pop-up. In that dialogue box, select advanced.
Find the proxy option and enter in the IP and port of the server you want to forward traffic to.
Android speaks SOCKS and so long as your proxy speaks SOCKS as well, you are good to go. If you root the device you can (depending on your version of Android), configure this proxy automatically. See, for instance, AdBlock Plus for Android which does exactly that.
If you don't want to go the proxy route you may be able to manually set ebtables rules if your device is rooted. This is significantly more work as you have to be careful not to mess up the NAT'ing that your device is already doing.
I want to develop an android application that can access blocked website. I thought about changing DNS address but Android give permission only for wifi dns address changing. I have also searched about using proxy sites but i couldn't make it . I'm searching for more compatible solution .
I'm waiting your suggestions. Thanks in advance.
There are many types of block which can be applied to a user on a mobile network.
The one you are referring to is done via DNS and I suspect you want to do such a thing because Android does not provide an interface to change DNS when you are using a mobile connection.
In that case is necessary to use root privileges. Your app will be running only on a rooted device. So you need to learn how to run a command using su. A good way to learn is to take a look to an open source root app such as Ad-Away.
To change DNS for a mobile network is necessary to know the Android version: in KitKat the DNS resolution is done through the netd daemon which ignores changes made via setprop. In Android <4.4 many DNS changer apps used commands like these
setprop dhcp.eth0.dns1 8.8.8.8
setprop dhcp.eth0.dns2 8.8.4.4
For Android 4.4 I wrote an app called Override DNS which uses a different set of commands.
Internet censorship can be done on other different levels.
I think the best way to circumvent any kind of block is to host a VPN server on a VPS located in USA or Europe and to activate a VPN from Android device. With this method any kind of network communication can be sent through the VPN so there's no problem related to DNS etc. In this scenario there's no need to have root privileges (depending on the VPN technology choosen).
I have an Android device. I need to forward packets arriving at the external IP to an internal IP to which Android is connected to.
I would like to know if I can write an App to enable this forwarding.
Also, if this doesn't what is the conventional way this is done. If I should use some scripts where should I place them??
And oh, can I test this using an android emulator??
Thanks.
It is may be possible to emulate a behavior like port forwarding but not routing for non rooted devices.
Also if you want to forward traffic from the mobile network to the wlan this is so far I know not possible. Android switches the connetion between mobile network and wlan. It is not possible to use both. Except some hot spot use cases.
I need to get the netmask and ip from the Android so I can calculate all the IP's within my subnet range.
I've been searching and so far I've found this:
Programmatically getting the gateway and subnet mask details
The problem is that it doesn't work for all devices. For instance, it doesn't work in the emulator (any Android version) and it doesn't work either in my Archos 7HT with Android 1.5.
It returns 0 for netmask and gateway.
Is there any way to do it? Is there any system file which I could read that contains this info?? (something like this: http://www.flattermann.net/2011/02/android-howto-find-the-hardware-mac-address-of-a-remote-host/).
In my advanced wifi settings I can see these settings, so there must be a way to retrieve them...
Thanks.
Try with APIs InetAddress and NetworkInterface. Emulator has no WIFI, hence is not possible to get address with Wifi API.
Check this reply