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

I am looking for a way to configure my Ethernet card with Java. Is there a way to change the default gateway, IP address and subnet mask in Java.

I am currently using OSHI to get the IP address, Mac address, and other hardware information. I also understand that the only way to set these parameters is with the Java.lang.Runtime Class and use the special Hardware command to set the properties from here

I am looking for a cleaner way to do this for Linux, Windows and Mac. I am basically trying to set all these properties from my own application. Is there a library or shell, such as OSHI, to execute a specific host command?

+7
java networking ethernet static-ip-address
source share
1 answer

You can do something like this

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); 
+3
source share

All Articles