Reputation: 2762
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
Upvotes: 4
Views: 2819
Reputation: 80761
Your problem looks very similar to this one in stackoverflow, maybe the answer will help you ;)
Upvotes: 7