Check the host is down or unknow by InetAddress

getByName

public static InetAddress getByName(String host)
                             throws UnknownHostException
Determines the IP address of a host, given the host's name. The host name can either be a machine name, such as "java.sun.com", or a textual representation of its IP address. If a literal IP address is supplied, only the validity of the address format is checked.
For host specified in literal IPv6 address, either the form defined in RFC 2732 or the literal IPv6 address format defined in RFC 2373 is accepted.
If the host is null then an InetAddress representing an address of the loopback interface is returned. See RFC 3330 section 2 and RFC 2373 section 2.5.3.
Parameters:
host - the specified host, or null.
Returns:
an IP address for the given host name.
Throws:
UnknownHostException - if no IP address for the host could be found.
SecurityException - if a security manager exists and its checkConnect method doesn't allow the operation
 

Address = InetAddress.getByName("starwave.com");
System.out.println(Address); 
//starwave.com/204.202.129.90 

If the program thrown UnknownException <- the host is unknown rather than down.
 
 

留言

這個網誌中的熱門文章

Disable ionic's sidemenu content drag to toggle menu

Multiple writable mappings exist for the field. Only one may be defined as writable, all others must be specified read-only.

java.lang.NoClassDefFoundError: org/apache/xerces/jaxp/datatype/XMLGregorianCalendarImpl$Parser