Pages Navigation Menu

Coding is much easier than you think

Getting Hostname from IP Address

Getting Hostname from IP Address

 

The below java code is used to Getting Hostname from IP Address
 

package com.simplecode;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Scanner;

public class Hostname {

	public static void main(String[] arg) {
		Scanner scanIn = new Scanner(System.in);
		String IpAddress = scanIn.nextLine();
		try {
			InetAddress addresses = InetAddress.getByName(IpAddress);

			String hostName = addresses.getHostName();
			System.out.println(hostName);

		}

        catch (UnknownHostException e) {
             System.out.println("Could not resolve IP Address to Hostname. Host Unknown !");
		}

	}
}

 

dwd2
Download It €- IpAddress

 

About Mohaideen Jamil