Sunday, 8 April 2018

Implementation of Name Resolution Protocol Using Java

import java.util.*;
import java.io.*;
import java.net.*;

public class NameResolution
{
public static void main(String arg[])
throws IOException
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the URL: ");
String name = sc.next();
try
{
InetAddress ip = InetAddress.getByName(name);
System.out.println("IP Address : "+ip.getHostAddress());
}
catch(UnknownHostException e)
{
System.out.println("\n No Such Host Found");
}
}
}

/*
aiktc@aiktc38 ~ $ cd Desktop
aiktc@aiktc38 ~/Desktop $ javac NameResolution.java
aiktc@aiktc38 ~/Desktop $ java NameResolution

Enter the URL:
www.wwe.com
IP Address : 104.80.51.135

aiktc@aiktc38 ~/Desktop $ javac NameResolution.java
aiktc@aiktc38 ~/Desktop $ java NameResolution
Enter the URL:
www.facebook.com 
IP Address : 31.13.78.35

aiktc@aiktc38 ~/Desktop $ javac NameResolution.java
aiktc@aiktc38 ~/Desktop $ java NameResolution
Enter the URL:
aiktc 
No Such Host Found
*/

No comments:

Post a Comment