44 lines
1.7 KiB
Java
44 lines
1.7 KiB
Java
import java.net.InetAddress;
|
|
import java.net.UnknownHostException;
|
|
import java.net.SocketException;
|
|
import java.net.NetworkInterface;
|
|
|
|
public class MACAdresse {
|
|
public static void main( String args[] ) {
|
|
try {
|
|
InetAddress iaddr1 = InetAddress.getByName("www.fh-dortmund.de");
|
|
InetAddress iaddr2 = InetAddress.getLocalHost();
|
|
InetAddress iaddr3 = InetAddress.getByName("localhost");
|
|
System.out.println(iaddr1.getHostName() + ": " + iaddr1.getHostAddress());
|
|
System.out.println(iaddr2.getHostName() + ": " + iaddr2.getHostAddress());
|
|
System.out.println(iaddr3.getHostName() + ": " + iaddr3.getHostAddress());
|
|
System.out.println();
|
|
|
|
byte[] ip = iaddr3.getAddress();
|
|
for(int i = 0; i < ip.length; i++) {
|
|
System.out.println(i + ": " + ip[i]);
|
|
}
|
|
System.out.println();
|
|
|
|
InetAddress[] iaddr4 = InetAddress.getAllByName("www.adeso.de");
|
|
for (int i = 0; i < iaddr4.length; i++) {
|
|
System.out.println(i + ": " + iaddr4[i].getHostName() + ": " + iaddr4[i].getHostAddress());
|
|
}
|
|
System.out.println();
|
|
|
|
var net = NetworkInterface.getByName("eth0");
|
|
byte[] macAdress = net.getHardwareAddress();
|
|
for (int i = 0; i < macAdress.length; i++) {
|
|
System.out.println(i + ": " + macAdress[i]);
|
|
}
|
|
}
|
|
catch (UnknownHostException e) {
|
|
System.out.println( "Host nicht bekannt: " + e );
|
|
}
|
|
catch (SocketException e) {
|
|
System.out.println("Socket exception: " + e);
|
|
}
|
|
}
|
|
|
|
}
|