Is it possible to change to IP address of the machine using Java?
Something equivalent to this linux command:
ifconfig eth0 [new-ip-address]
Is it possible to change to IP address of the machine using Java?
Something equivalent to this linux command:
ifconfig eth0 [new-ip-address]
well java.net.NetworkInterface
provides the information about your network interface. But, the IP address of your machine is highly OS specific. I don't think there is an easy way to change it though.
Furthur, the IP address is automatically assigned by DHCP.(I you use DHCP as pointed out by Thilo)
however I have successfully implemented a code which could run some of the DOS commands using java.lang.Runtime
class.
So, you can try to assign static IP address using netsh int ip set address "local area connection" static 192.168.0.101 255.255.255.0 192.168.0.254 1
type of DOS command in java.
I don't think there is a platform independent way but you can find the OS information using these links
1.Using Java to get os level system Information
2.Finding Operating System Information
3.How to get System Information using Java
you can use some if-else statements based on the system info then call the respective commands