How to set the default gateway, IP address and subnet mask from Java?

I'm looking for some ways to configure my Ethernet card from Java There is no way to change the default gateway, IP address and subnet mask from Java

At present, I am using oshi to obtain IP address, MAC address and other hardware information I also understand that the only way to set these parameters is Java Lang. runtime class and use hardware specific commands to set the properties of here

I'm looking for a cleaner way to do this for Linux, windows and MAC I'm basically trying to set all these properties from my own application Is there a library or wrapper like oshi to execute host specific commands?

Solution

You can do such a thing

String str1="192.168.0.201";
String str2="255.255.255.0";
String[] command1 = { "netsh","interface","ip","set","address","name=","Local Area Connection","source=static","addr=",str1,"mask=",str2};
Process pp = java.lang.Runtime.getRuntime().exec(command1);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>