Get Host Data

Friday 24 January 2014


If we want to know about Host data for example Ip address,pc name,operating system etc.
To do this job we have to first Import java.net package,
on Jbutton action performed as you see below 

 

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  
try
{
String[] xy=new String[] {java.net.InetAddress.getLocalHost ().getCanonicalHostName(),java.net.InetAddress.getLocalHost().getHostAddress
(),System.getProperty("user.name"),System.getProperty("os.name")};

jLabel1.setText("Your PC Name="+s1[0]+", Your Ip Address="+s1[1]+", your User
Name="+xy[2]+", Your Os="+xy[3]);

}
catch(UnknownHostException nyu)
{

jLabel1.setText(nyu);
}

}

0 comments:

Paste Long Url