Created
September 24, 2012 15:15
-
-
Save timpulver/3776469 to your computer and use it in GitHub Desktop.
[Java] URL to IP address lookup [host, url, ip, server, convert, conversion]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.net.*; | |
import java.io.*; | |
public static class IpFromUrl { | |
// Returns the IP address of an URL | |
// i.e. http://www.facebook.com -> 123.456.789.10 | |
public static String getIp( String hostname ) throws IOException { | |
try { | |
InetAddress ipaddress = InetAddress.getByName(hostname); | |
System.out.println("IP address: " + ipaddress.getHostAddress()); | |
return ipaddress.getHostAddress(); | |
} | |
catch ( UnknownHostException e ){ | |
System.out.println("Could not find IP address for: " + hostname); | |
throw new IOException("Could not find IP address for: " + hostname); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment