/**
 * @author lhebert
 */

import java.net.InetAddress;
import java.net.UnknownHostException;

public class JavaDNS {

    public static void main(String[] args) {

        try {
            // Get the local host address and hostname
            InetAddress localHost = InetAddress.getLocalHost();
            
            // Display local IP address and hostname
            System.out.println("Your current IP address : " + localHost.getHostAddress());
            System.out.println("Your current Hostname : " + localHost.getHostName());

            // Perform a reverse DNS lookup using the local IP address
            InetAddress reverseLookup = InetAddress.getByName(localHost.getHostAddress());
            System.out.println("Reverse Lookup Hostname: " + reverseLookup.getCanonicalHostName());
        } catch (UnknownHostException e) {
            System.err.println("Error occurred during DNS lookup: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
