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




Have Programming Question? Ask it here!
 
 
 


samar
IP converson
1 Answer(s)      3 years and 6 months 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
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, 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
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
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
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
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
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
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
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
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
To retrieve the IP address from Host Name, vice-versac
To retrieve the IP address from Host Name, vice-versa... to explain the method to find out the IP address from host name and to vice verse. Here... with getHostAddress() which return the IP address of that Host . If the user enter any
How To Unblock IP address from command line in CSF Firewall ââ?¬â?? Linux Server?
How To Unblock IP address from command line in CSF Firewall ΓΆβ?¬β?? Linux Server?  Hi, How To Unblock IP address from command line in CSF Firewall... the ip and then restart the csf server using following command: csf -r
Guys Help me with this Application(when you put the name of the website it will return the IP of the web)
it will return the IP of the web)  import java.awt.*; import java.awt.event....: ",Label.RIGHT); ok=new Button("Get IP...,MalformedURLException{ new MyApp(); InetAddress ip
Guys Help me with this Application(when you put the name of the website it will return the IP of the web)
it will return the IP of the web)  import java.awt.*; import java.awt.event....: ",Label.RIGHT); ok=new Button("Get IP...,MalformedURLException{ new MyApp(); InetAddress ip
Overview of Networking through JAVA,Find the Host name in reverse of given IP address
Find the Host name in reverse of given IP address... and create a class object and pass the IP address in InetAddress.getByName() method. Now retrieve the Host name of the IP address what we are pass in getByName
Overview of Networking through JAVA,To retrieve the IP address from Host Name, vice-versa
To retrieve the IP address from Host Name, vice-versa... to explain the method to find out the IP address from host name and to vice verse. Here... with getHostAddress() which return the IP address of that Host . If the user enter any
Find the Host name in reverse of given IP address
Find the Host name in reverse of given IP address... and create a class object and pass the IP address in InetAddress.getByName() method. Now retrieve the Host name of the IP address what we are pass in getByName
java inetaddress
; This class of java in "java.net" represents an Internet Protocol (IP) address. InetAddress class is used to create and manipulate IP objects. It does... useful methods for obtaining host names and IP addresses, to check
VoIP Wiki
; VoIP Matrix Wiki The Global IP Alliance, a consortium of IP and VoIP... of information covering IP-based communications technology and regulations... on IP and VoIP developments. We acknowledge that technology can solve many
Multicast Client in Java
to send and receive the IP packet or message by multicast client. Here, we provide... identified by the specific IP('224.0.0.0', '235.0.0.1', '235.255.0.1', '224.0.255.1') and port number(5000). Those of any client sends and receives IP packet
VoIP Providers List
;  Comparison of VoIP Service Providers Voice over IP... another without necessarily knowing their IP address (although IP based dialling... IP) section where you can find VoIP Providers. Here we have indexed best VoIP
VoIP User
; VoIP User-The Voice of IP telephony This website is an independent information guide dedicated to the subject of Voice IP telephony over...; Open-source VoIP user urges caution Despite building a working IP telephony
What is IPv6?
What is IPv6?       IP stands for Internet Protocol and v6 denotes it's version no 6. It is also known  as IPng  that stands for  IP Next Generation. At present 
VoIP Products
and applications of Voice over IP, it is too good to resist. Perhaps that is why... the issues and some services currently available.    Voice over IP... into existing PBX and IP infrastructures, making them the ideal choice for service
VoIP PBX Open Source
;    Open  Source IP PBX Digium has released the second beta of a "software appliance" version of Asterisk, the open source IP PBX... evaluation.    Open source free IP PBX An open source group
ReadIPAddress
getByName() method of InetAddress class to create a object that contains IP address for the given host name. Using this object we can get IP... to print this value. If the user enters the host name by keyboard then IP address
Using Log Files
(IP), Http status, date, time, bytes sent, bytes recieved, number of clicks etc...(" User IP: " + address +  ...; + "The User IP address is "+ address + "method
VoIP Termination
via the XO IP network to terminate an IP-originated call to the Public Switched... feature of VoIP Termination provides are follow here:-* Connectivity from an IP... Multiplex ("TDM") * Reliable intercity transport via the vast XO IP
AJAX Example
AJAX Example       In the following example we will see how to display server IP address dynamically with the help of AJAX, HTML, & PHP. SimpleAjax.html <html> <body>
Advertisements
 

 

 

DMCA.com