IP converson

IP converson

How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com?
View Answers

October 25, 2010 at 4:21 PM

Hi,

Here is the answer.

We get the hostname of the local ip address. This example is helpful for you.

import java.net.InetAddress;

import java.net.UnknownHostException;

public class staticdemo {

    public static void main(String[] args) {
        try {
            InetAddress localaddr = InetAddress.getLocalHost();
            System.out.println("main Local IP Address : "
                    + localaddr.getHostAddress());
            System.out.println("main Local hostname   : "
                    + localaddr.getHostName());
            System.out.println();

            InetAddress[] localaddrs = InetAddress.getAllByName("localhost");
            for (int i = 0; i < localaddrs.length; i++) {
                if (!localaddrs[i].equals(localaddr)) {
                    System.out.println("alt  Local IP Address : "
                            + localaddrs[i].getHostAddress());
                    System.out.println("alt  Local hostname   : "
                            + localaddrs[i].getHostName());
                    System.out.println();
                }
            }
        } catch (UnknownHostException e) {
            System.err.println("Can't detect localhost : " + e);
        }
    }

}

Thanks.









Related Tutorials/Questions & Answers:
IP converson
IP converson  How do I convert a numeric IP address like 192.18.97.39 into a hostname like java.sun.com
What is IP?
What is IP?   hello, What is IP?   hii,ADS_TO_REPLACE_1 Internet Protocol (IP) is an unreliable, best effort delivery, connection-less protocol used for transmitting and receiving data between hosts in a TCP/IP
Advertisements
ModuleNotFoundError: No module named 'ip'
ModuleNotFoundError: No module named 'ip'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip' How to remove the ModuleNotFoundError: No module named 'ip' error
Getting IP Address
Getting IP Address  Hi... i want to get the ip address of the current machine running my jsp program.... example: my ip is 172.16.11.247... from other system if i run my jsp program using my ip like 172.16.11.247/myfile.jsp i
Getting IP Address
Getting IP Address  Hi... i want to get the ip address of the current machine running my jsp program.... example: my ip is 172.16.11.247... from other system if i run my jsp program using my ip like 172.16.11.247/myfile.jsp i
IP Locator
IP Locator       IP Locator is a site based on the aiaxian google maps api, the user enters an Internet IP address to know the location of this ip in the global map. Enter the IP address
IP Address validation
IP Address validation  hi,I m now working with my final yr project,nd stuck in th middle i don't know how to validate the IP address in a JText field...(ie) the user shld enter the IP address in JTxt and when he hit the 'Submit
Get GMT from IP
Get GMT from IP  How do I get GMT value from IP address?? Thanx in Adv
How TCP/IP works ?
How TCP/IP works ?  hello,, Can some body tell me how TCP/IP works?   hii,ADS_TO_REPLACE_1 TCP/IP is just a protocol that allows different nodes on the network/Internet to share resources and without TRANSMISSION
Getting IP address of All the machines
Getting IP address of All the machines  Program how to fetch All the IP address on my domain(LAN) in java
problem in sending data from one ip to another ip in JAVA
problem in sending data from one ip to another ip in JAVA  Hi guys . this is naveen kumar...i need a help. i want to connect one ip to another ip (like ping),after that i want send the data with my system(Ip) to another ip
Version of com.bol>ip-resource dependency
List of Version of com.bol>ip-resource dependency
Version of com.hynnet>xdevelop-ip dependency
List of Version of com.hynnet>xdevelop-ip dependency
ModuleNotFoundError: No module named 'ip-api'
ModuleNotFoundError: No module named 'ip-api'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-api' How to remove the ModuleNotFoundError: No module named 'ip-api'
ModuleNotFoundError: No module named 'ip_intelligence'
ModuleNotFoundError: No module named 'ip_intelligence'  Hi, My... named 'ip_intelligence' How to remove the ModuleNotFoundError: No module named 'ip_intelligence' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'ip-liberator'
ModuleNotFoundError: No module named 'ip-liberator'  Hi, My Python... 'ip-liberator' How to remove the ModuleNotFoundError: No module named 'ip-liberator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'ip-utils'
ModuleNotFoundError: No module named 'ip-utils'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-utils' How to remove the ModuleNotFoundError: No module named 'ip-utils
ModuleNotFoundError: No module named 'my-ip'
ModuleNotFoundError: No module named 'my-ip'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-ip' How to remove the ModuleNotFoundError: No module named 'my-ip'
ModuleNotFoundError: No module named 'update-ip'
ModuleNotFoundError: No module named 'update-ip'  Hi, My Python... 'update-ip' How to remove the ModuleNotFoundError: No module named 'update-ip' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'be-proxy-ip'
ModuleNotFoundError: No module named 'be-proxy-ip'  Hi, My Python... 'be-proxy-ip' How to remove the ModuleNotFoundError: No module named 'be-proxy-ip' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'cz-ip'
ModuleNotFoundError: No module named 'cz-ip'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'cz-ip' How to remove the ModuleNotFoundError: No module named 'cz-ip'
ModuleNotFoundError: No module named 'external-ip'
ModuleNotFoundError: No module named 'external-ip'  Hi, My Python... 'external-ip' How to remove the ModuleNotFoundError: No module named 'external-ip' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'ip-address'
ModuleNotFoundError: No module named 'ip-address'  Hi, My Python... 'ip-address' How to remove the ModuleNotFoundError: No module named 'ip... have to install padas library. You can install ip-address python
ModuleNotFoundError: No module named 'ip-country'
ModuleNotFoundError: No module named 'ip-country'  Hi, My Python... 'ip-country' How to remove the ModuleNotFoundError: No module named 'ip... have to install padas library. You can install ip-country python
ModuleNotFoundError: No module named 'ip-lib'
ModuleNotFoundError: No module named 'ip-lib'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-lib' How to remove the ModuleNotFoundError: No module named 'ip-lib'
ModuleNotFoundError: No module named 'ip-query'
ModuleNotFoundError: No module named 'ip-query'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-query' How to remove the ModuleNotFoundError: No module named 'ip-query
ModuleNotFoundError: No module named 'ip-utils'
ModuleNotFoundError: No module named 'ip-utils'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-utils' How to remove the ModuleNotFoundError: No module named 'ip-utils
ModuleNotFoundError: No module named 'check-ip'
ModuleNotFoundError: No module named 'check-ip'  Hi, My Python... 'check-ip' How to remove the ModuleNotFoundError: No module named 'check-ip... to install padas library. You can install check-ip python with following
ModuleNotFoundError: No module named 'django-ip'
ModuleNotFoundError: No module named 'django-ip'  Hi, My Python... 'django-ip' How to remove the ModuleNotFoundError: No module named 'django-ip' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'ip-address'
ModuleNotFoundError: No module named 'ip-address'  Hi, My Python... 'ip-address' How to remove the ModuleNotFoundError: No module named 'ip... have to install padas library. You can install ip-address python
ModuleNotFoundError: No module named 'ip-api'
ModuleNotFoundError: No module named 'ip-api'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-api' How to remove the ModuleNotFoundError: No module named 'ip-api'
ModuleNotFoundError: No module named 'ip-api'
ModuleNotFoundError: No module named 'ip-api'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-api' How to remove the ModuleNotFoundError: No module named 'ip-api'
ModuleNotFoundError: No module named 'ip_info'
ModuleNotFoundError: No module named 'ip_info'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip_info' How to remove the ModuleNotFoundError: No module named 'ip_info
ModuleNotFoundError: No module named 'ip-inspector'
ModuleNotFoundError: No module named 'ip-inspector'  Hi, My Python... 'ip-inspector' How to remove the ModuleNotFoundError: No module named 'ip-inspector' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'ip-lib'
ModuleNotFoundError: No module named 'ip-lib'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-lib' How to remove the ModuleNotFoundError: No module named 'ip-lib'
ModuleNotFoundError: No module named 'ip-liberator'
ModuleNotFoundError: No module named 'ip-liberator'  Hi, My Python... 'ip-liberator' How to remove the ModuleNotFoundError: No module named 'ip-liberator' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'IP-Link'
ModuleNotFoundError: No module named 'IP-Link'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'IP-Link' How to remove the ModuleNotFoundError: No module named 'IP-Link
ModuleNotFoundError: No module named 'ip-utils'
ModuleNotFoundError: No module named 'ip-utils'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-utils' How to remove the ModuleNotFoundError: No module named 'ip-utils
ModuleNotFoundError: No module named 'log-ip'
ModuleNotFoundError: No module named 'log-ip'  Hi, My Python...-ip' How to remove the ModuleNotFoundError: No module named 'log-ip'... to install padas library. You can install log-ip python with following command
ModuleNotFoundError: No module named 'my-ip'
ModuleNotFoundError: No module named 'my-ip'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'my-ip' How to remove the ModuleNotFoundError: No module named 'my-ip'
ModuleNotFoundError: No module named 'pywe-ip'
ModuleNotFoundError: No module named 'pywe-ip'  Hi, My Python...-ip' How to remove the ModuleNotFoundError: No module named 'pywe-ip... to install padas library. You can install pywe-ip python with following command
ModuleNotFoundError: No module named 'spiro-ip'
ModuleNotFoundError: No module named 'spiro-ip'  Hi, My Python... 'spiro-ip' How to remove the ModuleNotFoundError: No module named 'spiro-ip... to install padas library. You can install spiro-ip python with following
ModuleNotFoundError: No module named 'vs-ip'
ModuleNotFoundError: No module named 'vs-ip'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'vs-ip' How to remove the ModuleNotFoundError: No module named 'vs-ip'
ModuleNotFoundError: No module named 'wadofstuff-ip'
ModuleNotFoundError: No module named 'wadofstuff-ip'  Hi, My... 'wadofstuff-ip' How to remove the ModuleNotFoundError: No module named 'wadofstuff-ip' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'check-ip'
ModuleNotFoundError: No module named 'check-ip'  Hi, My Python... 'check-ip' How to remove the ModuleNotFoundError: No module named 'check-ip... to install padas library. You can install check-ip python with following
ModuleNotFoundError: No module named 'dev-ip'
ModuleNotFoundError: No module named 'dev-ip'  Hi, My Python...-ip' How to remove the ModuleNotFoundError: No module named 'dev-ip'... to install padas library. You can install dev-ip python with following command
ModuleNotFoundError: No module named 'django-ip'
ModuleNotFoundError: No module named 'django-ip'  Hi, My Python... 'django-ip' How to remove the ModuleNotFoundError: No module named 'django-ip' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'generate_ip'
ModuleNotFoundError: No module named 'generate_ip'  Hi, My Python... 'generate_ip' How to remove the ModuleNotFoundError: No module named 'generate_ip' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'Get_ip'
ModuleNotFoundError: No module named 'Get_ip'  Hi, My Python..._ip' How to remove the ModuleNotFoundError: No module named 'Get_ip'... to install padas library. You can install Get_ip python with following command
ModuleNotFoundError: No module named 'ip-api'
ModuleNotFoundError: No module named 'ip-api'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'ip-api' How to remove the ModuleNotFoundError: No module named 'ip-api'

Ads