Assign static IP to ethernet card from OTG

2020-07-17 15:12发布

问题:

I would like to assign a static IP to an ethernet card, connected to the Android device via OTG cable. It should be done programmatically, but I can't find any reference regarding ethernet cards in android.

Any ideas?

Thank you

回答1:

If its a rooted device you can try with this

Process process = Runtime.getRuntime().exec(new String[] { "su", "-c", "netcfg eth0 192.168.0.123"});
process.waitFor();

And also you can use ifconfig instead of netcfg.