I am trying to create a Java program to retrieve my systems IP address using Java. On the click of a button, the IP address is displayed is a text box.
Now the problem is, everytime I use the code
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
jTextField1.setText(Inet4Address.getLocalHost().toString());
} catch (UnknownHostException ex) {
jTextField1.setText("IP not found");
}
}
It only retrieves my loopback IP and not the static IP which I have configured in Ubuntu which is of the range 192.16x.xxx.xxx This piece of code works fine on my windows 7 but not on Ubuntu 11.04, I dont know why...!!! I dont wanna use windows for developing applications or anything.
Just 2 questions I have
- How do I retrieve my systems static IP ?
- If java is cross-platform, why does this piece of code works well on windows & not on Ubuntu ?