100% found this document useful (1 vote)
1K views2 pages

Xiii. Develop A Program Using Inetaddress Class To Retrive Ip Address of Computer When Hostname Is Entered by The User

This Java program uses the InetAddress class to retrieve the IP address associated with a hostname entered by the user. The user enters a hostname, which is passed to the getByName() method to retrieve the InetAddress object. Then the getHostName() and getHostAddress() methods are used to output the hostname and IP address associated with the InetAddress.

Uploaded by

Mayur Narsale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
1K views2 pages

Xiii. Develop A Program Using Inetaddress Class To Retrive Ip Address of Computer When Hostname Is Entered by The User

This Java program uses the InetAddress class to retrieve the IP address associated with a hostname entered by the user. The user enters a hostname, which is passed to the getByName() method to retrieve the InetAddress object. Then the getHostName() and getHostAddress() methods are used to output the hostname and IP address associated with the InetAddress.

Uploaded by

Mayur Narsale
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

XIII.

Develop A Program Using InetAddress Class To Retrive IP Address Of Computer When


Hostname Is Entered By The User.

import java.net.*;

import java.util.*;

public class Practical_14

public static void main(String [] args)

try

InetAddress ip=InetAddress.getByName("www.facebook.com");

System.out.println("Host Name: "+ip.getHostName());

System.out.println("IP Address: "+ip.getHostAddress());

catch(Exception e)

System.out.println(e);

You might also like