I'm interested in adding an additional ipv4 local network ip address from a java application (actually Scala). So far, the only solution I've found is runtime exec of netsh
, but I'd prefer not to have a dependency on netsh
and use core java libraries if possible. What's the best solution for this? Moreover, it looks like even netsh
won't work for me since I'm on linux.
You could make a call to ifconfig
(or ipconfig
/ netsh
for windows).
Using the following command:
ifconfig eth0 <NEW-IP> netmask 255.255.255.0 up
In Java:
Process p = Runtime.getRuntime().exec(new String[]{"bash","-c","ifconfig eth0 <NEW-IP> netmask 255.255.255.0 up"});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.