Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Get IP address by its name.

  Asked By: Jeff    Date: Apr 12    Category: Java    Views: 3808

I would like to share my exprience. I find at
java.net.InetAddress ,class InetAddress has a method called
getByname(); so we can get the Ip address by its host
name. For example ,InetAddress
address=InetAddress.getByname("localhost"). and the value of address is



1 Answer Found

Answer #1    Answered By: Silk Choco     Answered On: Apr 04

Well ! i have tried the following code snippet using try -catch block statement to get ip address using its name :

java.net.InetAddress inetAdd =
java.net.InetAddress.getByName("enter the host name");
System.out.println ("IP Address is : " + inetAdd.getHostAddress());
catch(catch(java.net.UnknownHostException uhe)
//handle exception

In catch block, i used user-defined exception to handle the errors. Instead of coding you can also get ip by its name through online sites like http://www.ip-details.com/domain-host-search/ .

Didn't find what you were looking for? Find more on Get IP address by its name. Or get search suggestion and latest updates.