Package com.howin.util;
Import java.net.*; public class Ipconfig {public static void main (string[] args) throws Exception {//TODO auto-generated met
Hod stub inetaddress ia=null;
try {ia=ia.getlocalhost ();
String Localname=ia.gethostname ();
String localip=ia.gethostaddress ();
SYSTEM.OUT.PRINTLN ("This machine name is:" + localname);
SYSTEM.OUT.PRINTLN ("The IP of this machine is:" +localip);
catch (Exception e) {//TODO auto-generated catch block E.printstacktrace (); InetAddress ia1 = Inetaddress.getlocalhost ();//Get local IP object System.out.println ("MAC ...).
"+getmacaddress (IA1)); //Get MAC Address method private static String getmacaddress (InetAddress ia) throws exception{//Get Network Interface object (that is, NIC) and get
To the MAC address, the MAC address exists in a byte array.
Byte[] mac = Networkinterface.getbyinetaddress (IA). Gethardwareaddress (); The following code is to assemble the MAC address into StrinG StringBuffer sb = new StringBuffer ();
for (int i=0;i<mac.length;i++) {if (i!=0) {sb.append ("-");
}//mac[i] & 0xFF is to convert the byte to a positive integer String s = integer.tohexstring (Mac[i] & 0xFF);
System.out.println ("--------------");
System.err.println (s);
Sb.append (S.length () ==1?0+s:s);
To capitalize all lowercase letters of the string into a regular MAC address and return Sb.tostring (). toUpperCase (); }
}