<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">
import java.util.*;
import java.net.*;

public class TestAddr {
  public static void main (String[] args) {
	try {
	  // pobranie danych lokalnego hosta
	  InetAddress adres1 = InetAddress.getLocalHost();
	  System.out.println("Nazwa lokalnego hosta: " + adres1.getHostName());
	  System.out.println("Adres lokalnego hosta: " + adres1.getHostAddress() + "\n");

	  // pobranie danych hosta o znanej nazwie
	  InetAddress adres2 = InetAddress.getByName("snickers.ek.univ.gda.pl");
	  System.out.println("Nazwa: " + adres2.getHostName());
	  System.out.println("Adres: " + adres2.getHostAddress() + "\n");

	  // pobranie danych hosta o znanym adresie IP
	  InetAddress adres3 = InetAddress.getByName("153.19.120.250");
	  System.out.println("Nazwa: " + adres3.getHostName());
	  System.out.println("Adres: " + adres3.getHostAddress() + "\n");

	  // pobranie adresu lokalnego hosta w postaci tablicy bajtów
	  byte[] address = adres1.getAddress();
	  for(int i=0; i&lt;address.length; i++) {
	    byte signedByte = address[i];
	    int unsignedByte = signedByte &lt; 0 ? signedByte + 256 : signedByte;
	    System.out.print(unsignedByte);
	    if ( i != address.length-1 ) System.out.print(":");
	  }	  
	  System.out.println("\n");

	  NetworkInterface nint = NetworkInterface.getByInetAddress(adres1);
	  if (nint != null) System.out.println("Interfejs sieciowy: "+nint);
	  System.out.println("\n");

	  Enumeration interfaces = NetworkInterface.getNetworkInterfaces();
	  while (interfaces.hasMoreElements()) {
	    NetworkInterface ni = (NetworkInterface) interfaces.nextElement();
            System.out.println(ni);               
	  }  


	}
	catch (UnknownHostException e) {
	  System.err.println(e);
	}
	catch (SocketException ex) {
	  System.err.println("Could not list sockets");
	}

  } 
} 
</pre></body></html>