View RSS Feed

My Java Tips example

Rate this Entry
by , 11-03-2011 at 01:15 PM (2750 Views)
Each computer on internet is called a node or a host. Each host has unique address called Internet Protocol (IP) address. IP addresses are not easy for the humans to remember therefore, Domain Name System (DNS) was introduced. DNS assigns a human understandable name to IP addresses.

InetAddress class represents IP addresses which can be useful in networking environment. Let see what we can o with this one:

Following code finds and prints the IP address of a given web host. Please note that some hosts have more than one IP addresses therefore, we will get all the IP addresses in an array and then will print those.

Java Code:
try {
InetAddress[] addresses =
for (int i = 0; i < addresses.length; i++) {
catch (UnknownHostException ex) {
System.out.println("Could not find the host.");

Submit " example" to Facebook Submit " example" to Digg Submit " example" to Submit " example" to StumbleUpon Submit " example" to Google

Tags: None Add / Edit Tags
Java SE , Network Programming