Last active
April 10, 2019 06:58
-
-
Save roshanadh/0f402b3ef2a941fe61063562c54bb41a to your computer and use it in GitHub Desktop.
Get IP address from a given Hostname in Java
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 class HostNameDemo | |
{ | |
public static void main(String[] args) throws IOException | |
{ | |
System.out.println("Type the Host Name: "); | |
BufferedReader readName=new BufferedReader(new InputStreamReader(System.in)); | |
String hostName=readName.readLine(); | |
try{ | |
InetAddress host= InetAddress.getByName(hostName); | |
System.out.println("The address for "+hostName+" is: "+host.getHostAddress()); | |
} | |
catch(UnknownHostException e) | |
{ | |
System.out.println("IP address was not found for given Host name."); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment