// Iplabel. java
Import java.net .*;
Import java. awt .*;
Import javax. swing .*;
Public class iplabel
{
JFrame;
JLabel label1, label2;
JPanel;
String ip, address;
Public void getip ()
{
Try
{
InetAddress addr = InetAddress. getLocalHost ();
Ip = addr. getHostAddress (). toString (); // obtain the local IP address.
Address = addr. getHostName (). toString (); // obtain the local name
// System. out. println ("addr =:" + String. valueOf (addr ));
}
Catch (Exception e)
{
System. out. println ("Bad IP Address! "+ E );
}
}
Public void showframe ()
{
Frame = new JFrame ("my ip ");
Label1 = new JLabel ("this my ip ");
Label1.setText (ip );
Label2 = new JLabel ("this my address ");
Label2.setText (address );
Panel = new JPanel ();
Panel. add (label1 );
Panel. add (label2 );
Frame. getContentPane (). add (panel );
Frame. setSize (400,300 );
Frame. setVisible (true );
}
Public static void main (String agrs [])
{
Iplabel myip = new iplabel ();
Myip. getip ();
Myip. showframe ();
}
}