aufgabe 3
This commit is contained in:
32
praktikum-5/aufgabe1/InternetAdresse.java
Normal file
32
praktikum-5/aufgabe1/InternetAdresse.java
Normal file
@@ -0,0 +1,32 @@
|
||||
// DK, 18.11.2022
|
||||
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.InetAddress;
|
||||
|
||||
public class InternetAdresse {
|
||||
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());
|
||||
}
|
||||
}
|
||||
catch (UnknownHostException e) {
|
||||
System.out.println( "Host nicht bekannt" );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user