Reputation: 986
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.
Upvotes: 4
Views: 23528
Reputation: 41
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
Upvotes: 4
Reputation: 986
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";
Upvotes: 2