hi,
i am trying to get all the mac address of the localhost network interfaces.
here is my code. i don't seem to find what is wrong with it.
i will appreciate any help.
thanks
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
public class MAC {
public static void main(String[] args) {
try {
InetAddress[] addrs = null;
if((addrs = InetAddress.getAllByName("localhost")) == null) System.exit(1);
NetworkInterface ni = null;
for(int i = 0; i < addrs.length; ++i) {
if((ni = NetworkInterface.getByInetAddress(addrs)) == null) System.exit(2);
byte[] mac = null;
if((mac = ni.getHardwareAddress()) == null) System.exit(3);
System.out.println(addrs[i]);
System.out.println(new String(mac));
}
}
catch(UnknownHostException e) { System.out.println(e.getMessage()); }
catch(SocketException e) { System.out.println(e.getMessage()); }
}
}
Edited by: BigJ___ on Sep 9, 2010 2:44 AM