You are on page 1of 3

ADVANCE JAVA PROGRAMMING

Name :- Ayush Maroti Wadje Class : - CO5I


Roll No :- 76

Practical No 14 :- Write a Program To Demonstrate The Use Of InetAddress


Class And It’s Factory Methods

X. Program Code :
1. Execute The Following Code And Write The Output.

Code :-

import java.net.*;
public class InetDemoEx {
public static void main(String args[]) {
try {
InetAddress ip =
InetAddress.getByName("localhost");
System.out.println("Host Name: " +
ip.getHostName());
System.out.println("IP Address: " +
ip.getHostAddress());
} catch (Exception e) {
System.out.println(e);
}
}
}

1
Output :-

XIII. Exercise.

1. Develop a Program Using InetAddress Class To Retreive Ip Address Of


Computer When Hostname Is Entered By The User.
Code :-

import java.io.*;
import java.net.*;
public class InetDemoExample {
public static void main(String[] args){
try{
InetAddress
ip=InetAddress.getByName("www.Gmail.com");
System.out.println("Host Name:
"+ip.getHostName());
System.out.println("IP Address:
"+ip.getHostAddress());
}catch(Exception e){System.out.println(e);}
}
}

2
Output :-

You might also like