Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


samar
IP converson
1 Answer(s)      4 years ago
Posted in : Java Interview Questions


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

Advertisement
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, Internet Protocol (IP) is an unreliable, best effort delivery, connection-less protocol used for transmitting and receiving data between hosts in a TCP/IP network
Advertisements
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
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
Get GMT from IP
Get GMT from IP  How do I get GMT value from IP address?? Thanx in Adv
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
How TCP/IP works ?
How TCP/IP works ?  hello,, Can some body tell me how TCP/IP works?   hii, TCP/IP is just a protocol that allows different nodes on the network/Internet to share resources and without TRANSMISSION CONTROL PROTOCOL
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
PHP Get Browser IP Address
PHP Get Browser IP Address PHP provides us  $_SERVER['REMOTE_ADDR'] function is used to display the Browser IP address PHP Get IP Address Code: <?php echo "My Browser IP is :". $_SERVER['REMOTE_ADDR']; ?>
Get IP Address in Java
Get IP Address in Java In this example we will describe How to get ip address in java. An IP address is a numeric unique recognition number which...(). getHostAddress(). InetAddress():-The InetAddress is class represents an IP address
MultiClient-server tcp-ip with GUI in java
MultiClient-server tcp-ip with GUI in java  i wanna MultiClient-server tcp-ip with GUI in java
MultiClient-server tcp-ip with GUI in java
MultiClient-server tcp-ip with GUI in java  i wanna MultiClient-server tcp-ip with GUI in java
block IP of LAN machines from server - RMI
block IP of LAN machines from server  i want to block the IP... server. IP block means,I want to restrict them to access the internet. so, how is it possible to block IP of LAN machines from server
Visitor IP Address and Host Name using jsp
Visitor IP Address and Host Name using jsp  I have created one jsp page and i want to display the ip address of the visitor in my page. I used the following code to get the ip address: String ip=request.getRemoteAddr(); But i am
Get IP Example
Get IP Example       This example shows you ip address of your network...() : Network Interface class is used for get name, and a list of IP addresses
Get IP Address Example
Get IP Address Example       This example shows you ip address of your... : NetworkInterface.getNetworkInterfaces() : Network Interface class is used for get name, and a list of IP
Why do I need Dedicated IP?
A dedicated IP means that a website has its own IP address. When users type URL or the IP address it brings to the same domain name. Dedicated IP address is also called as static IP. It is an IP which is not shared by any other website
java get all ip addresses in a lan
java get all ip addresses in a lan  Anybody have any idea on using java or cpp on how to get the ip addresses of all the machines[win or linux... to know that a given ip address computer is connected in a LAN?. I could supply
PHP GD Get System IP
<?php $image = imagecreatetruecolor(150,70); $ip = "$_SERVER[REMOTE_ADDR]"; imagestring($image, 10, 20, 36, $ip, 0x00ff00); header('Content-Type: image/png'); imagepng($image, null, 9); ?> After
Java Get IP Address
Java Get IP Address       This section illustrates you how to obtain the IP Address of local host. An IP address is either a 32-bit or 128-bit unsigned number used
Find Exact Location from IP address in java?
Find Exact Location from IP address in java?  I am looking for API where we can pass IP address and get the location (Cityname,Country name). please suggest any API OR sample code. Thank you
Get System Ip
Get System Ip       The System IP address is a unique numerical identification... for a IP address is a 32- bit numeric address written as four number separated
IP Filter Example
IP Filter Example      ... for a firewall to determining what traffic passes through the firewall based on IP address... the risk from out side attacks is to filter incoming requests based on the IP address
finding the ip address of other system and store in the database - JDBC
finding the ip address of other system and store in the database  code to find the ip address,host name and their locale of other system... in database.if any other system tries to connect our system ,we have to find the ip address
Network IP Setting in Windows 8
is the 'Network IP Setting' of your PC. So, let us learn how to configure your Network IP in Windows 8 on your PC. 1. To access your Network IP setting... and click to 'OK' button.   8. Now, select 'Use the following IP address
how to get an lan system ip and mac address in java code
how to get an lan system ip and mac address in java code  strong text
Find Your Host Name/IP Address
Find Your Host Name/IP Address   ... the getLocalHost() method to print the Host name as well as the IP Address of the local... detect IP Address : " + e);   
Problem in setting IP address for a JFrame Class Desktop Application
Problem in setting IP address for a JFrame Class Desktop Application  I have designed a browser for our final year project, it is working well..., the browser is unable to load anything. I don't know how to set IP address for our
Java example program to get IP address of own system
Java example program to get IP address of own system       java get own IP address An IP... is assigned to the devices participating in the network for communication. To get IP
Advertisements
 

 

 

DMCA.com