How can you check whether domain exists or not in Java?

前端 未结 5 1228
死守一世寂寞
死守一世寂寞 2020-12-17 20:57

Suppose my email address is xyz@yahoo.com and I want to check if yahoo.com is a valid domain or not.

Can anyone tell me which Java API I ca

5条回答
  •  我在风中等你
    2020-12-17 21:10

    One thing that you could do is trying to resolve "yahoo.com". Something like this:

    public static void main(String[] args) throws UnknownHostException {
        InetAddress inetAddress = InetAddress.getByName("yahoo.com");
        System.out.println(inetAddress.getHostName());
        System.out.println(inetAddress.getHostAddress());
    }
    

    which outputs:

    yahoo.com
    67.195.160.76
    

提交回复
热议问题