Wednesday, November 30, 2016

Java Program to find IP address of Website

In this page we will understand and learn How to get IP address of any website by using Java programming language. Java Networking API provides the method to know IP address of any website. It is possible to know the IP address of website on Internet with the help of getByName() method of InetAddress class of java.net package. The InetAddress class is used to encapsulate both the numerical IP address and the domain name for that address. The InetAddress also includes the factory method getByaddress(),which takes an IP address and returns an InetAddress object. Either an IP4 or IP6 address can be used.




Let us understand and learn the concept with the fallowing example:

import java.io.*;
import java.net.*;
class InetAdressTest
{
public static void main(String[] args)throws UnknownHostException,IOException

{
BufferedReader br=new BufferedReader(new InputStreadReader(System.in));
System.out.println("enter a website name:");
String website=br.readLine();
try
{
InetAddress ip=InetAddress.getByName(website);
System.out.println(" The IP address is:"+ip);
}
catch(UnknownHostException ue)
{
System.out.println("Website not found");
}
}
}

Output:

I hope you enjoy this page and keep follow my blog for latest updates and share post to your friends through social websites like Facebook,google+,linkedin  etc... also comments about your answers on this concept.






No comments:

Post a Comment

High Paying Jobs after Learning Python

Everyone knows Python is one of the most demand Programming Language. It is a computer programming language to build web applications and sc...