| // tcptest.java - Applikation zum Ermitteln der TCP/IP-Adressen |
| import java.net.NetworkInterface; |
| import java.util.Enumeration; |
| import java.net.InetAddress; |
| public class tcptest { |
| /** |
| * @param args |
| */ |
| public static void main(String[] args) { |
| NetworkInterface iface = null; |
| System.out.println(); |
| try { |
| // Rechner-Name lang |
| System.out.println(InetAddress.getLocalHost().getCanonicalHostName()); |
| System.out.println(); |
| for (Enumeration ifaces = NetworkInterface.getNetworkInterfaces(); ifaces.hasMoreElements();) { |
| iface = (NetworkInterface) ifaces.nextElement(); |
| InetAddress ia = null; |
| for (Enumeration ips = iface.getInetAddresses(); ips.hasMoreElements();) { |
| ia = (InetAddress) ips.nextElement(); |
| // Netzwerk-Verbindung und TCP/IP-Adresse |
| System.out.print(iface.getName() + " --> " + ia.getHostAddress() ); |
| if (ia.getHostAddress().indexOf(":") >= 0) { |
| System.out.println("<-- IPv6"); |
| } else if (ia.getHostAddress().startsWith("127")) { |
| System.out.println("<-- localhost"); |
| } else System.out.println("<-- IPv4"); |
| } |
| } |
| } catch (Exception e) { |
| // Fehler |
| e.printStackTrace(); |
| } |
| } |
| } |
rechnername.domain.com
lo --> 0:0:0:0:0:0:0:1<-- IPv6
lo --> 127.0.0.1<-- localhost
eth3 --> fe80:0:0:0:c68:6a7a:b0b5:e2dd%10<-- IPv6
net3 --> fe80:0:0:0:f129:31c8:ec99:ef54%11<-- IPv6
net3 --> 192.168.178.21<-- IPv4
net4 --> 2001:0:5ef5:73ba:1cf0:3d35:3f57:4dea<-- IPv6
net4 --> fe80:0:0:0:1cf0:3d35:3f57:4dea%12<-- IPv6
net5 --> fe80:0:0:0:0:5efe:c0a8:b215%13<-- IPv6
In der Mitte stehen die TCP/IP-Adressen.
Die TCP/IP-Adresse 192.168.178.21 im Beispiel wurde von einem DSL-Router (DHCP-Server)
per WLAN-Adapter bezogen.