3

I have ethernet connected to my android board. I want to manually set IP from code. I was able to set IP address for WIFI. I have looked into following links for ethernet

Assign static IP to ethernet card from OTG So far I have not found how to set static IP to ethernet via android code.

Tushar Thakur
  • 956
  • 3
  • 15
  • 32

2 Answers2

3

You may need to create /data/misc/ethernet/ipconfig.txt file to configure static IP address.
As you successfully configured static IP address for WiFi already,
I think /data/misc/wifi/ipconfig.txt was also created and it will be valid for Ethernet config, too.
Please refer to following links for file path and data format.
EthernetConfigStore.java
IpConfigStore.java

That Agent
  • 31
  • 1
2

I was able to set Ip to Ethernet connection as follows. I was using Allwinner A31s android board.

String command1 = "su -c ifconfig eth0 "
                        + terminalIpAddressString+" netmask "
                        + subnetMaskAddressString
                        +" up";
                String command2 = "route add default gw "
                        + gatewayAddressString+" dev eth0";



                String command3 = "mount -o remount,rw /system";
                String command4 = "echo \"su -c ifconfig eth0 "
                        +terminalIpAddressString+" netmask "
                        +subnetMaskAddressString+" up;" +
                        "route add default gw "
                        +gatewayAddressString
                        +" dev eth0\" > /system/bin/preinstall.sh";

                String command5 = "busybox sed -i 's/su -c ifconfig eth0 "
                        +terminalIpAddressString
                        +" netmask "+subnetMaskAddressString+" up;"
                        +"route add default gw 172.19.10.2 dev eth0"
                        + "/su -c ifconfig eth0 "+terminalIpAddressString
                        +" netmask "+subnetMaskAddressString+" up;"
                        +"route add default gw "+gatewayAddressString
                        +" dev eth0/g' /system/bin/preinstall.sh";
Tushar Thakur
  • 956
  • 3
  • 15
  • 32