fbpx
Pages Navigation Menu

Coding is much easier than you think

Getting Hostname from IP Address

Getting Hostname from IP Address

In this Tutorial, I will discuss about retrieving Hostname from IP Address using Java.

 

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


I'm a Full stack developer of IT exp in J2EE, AngularJs, MicroServices, Docker, Spring (Boot, MVC, Cloud), Bluemix, DevOps. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.

Advertisements
%d bloggers like this: