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.util.Scanner;

public class Hostname {

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

			String hostName = addresses.getHostName();


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



Download It €- IpAddress


About Mohaideen Jamil

Am currently working as a Struts 2 Developer in a reputed IT Organisations. I can help you with teaching Core java and Struts 2. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.