0

I tried looking several posts and questions, but they all give solution for getting the Subnet Mask and none has provided method for setting the subnet mask via programming. Any solutions?

  • Hope [This Link](http://stackoverflow.com/questions/28283915/android-detect-local-ip-and-subnet-mask-for-wifi-both-while-tethering-and-conn)http://stackoverflow.com/questions/28283915/android-detect-local-ip-and-subnet-mask-for-wifi-both-while-tethering-and-conn will help you – chotemotelog Dec 14 '15 at 08:57
  • Its for getting only :D – Mike Walker Dec 14 '15 at 09:14
  • Try http://stackoverflow.com/questions/4106502/set-android-ip-dns-gateway-setting-programatically (not sure if that still works or not) – zapl Dec 14 '15 at 09:27

1 Answers1

0

I assume you want to set the network interfaces subnet mask for your device. This is not possible for security reasons. Android does not allow apps to change the network configuration to prevent them from malicious behaviour.

When root access is available, one might invoke shell commands from the app. To set the IP and subnet mask of a specified interface use:

ip addr add <ip>/<mask-bits> dev <interface>

example: ip addr add 192.168.3.162/24 dev eth1

to set eth1 IP to 192.168.3.162 with 255.255.255.0 as the subnet mask.

Jonas Köritz
  • 2,606
  • 21
  • 33