package org.academiadecodigo.enuminatti.inetaddress;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Scanner;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class DNSResolver {
    public static void main(String[] args) {

        String host = getHost();

        try {
            InetAddress resolvedHost = InetAddress.getByName(host);
            System.out.println(resolvedHost.isReachable(2000) ? "OK" : "Fail");
        } catch (UnknownHostException e) {
            System.out.println("Unknown host.");
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private static String getHost() {
        System.out.println("Ping host: ");
        Scanner scanner = new Scanner(System.in);
        return scanner.nextLine();
    }
}
