Determining the IP Address & Hostname of Local Computer in Java Last Updated : 04 Dec, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report IP Address Stands for Internet Protocol Address, is a numeric label that is assigned uniquely to each device connected within a computer network that uses the internet protocol. An IP address serves two principal functions: It identifies the host, or more specifically its network interface.It provides the location of the host in the network, and thus the capability of establishing a path to that host.The IP address also specifies the format of the data packets that are sent and received among routers and end systems. The IP address space is managed globally by the Internet Assigned Numbers Authority (IANA), and by five regional Internet registries (RIRs) responsible in their designated territories for assignment to local Internet registries, such as Internet service providers (ISPs), and other end users. IP versions: Two versions of IP addresses are most commonly seen in internet addressing these days. They are the IPv4 and IPv6. IPv4: IPv4 has a size of 32 bits, i.e., 4,294,967,296 addresses can be assigned using IPv4. IPv4 addresses are represented in dot-decimal notation, consisting of 4 decimal numbers separated by dots, each ranging from 0 to 255. Each part represents a group of 8 bits (an octet) of the address. i.e.192.168.0.118IPv6: In IPv6, the address size was increased from 32 bits in IPv4 to 128 bits, thus providing up to 2^128 (approximately 3.403×10^38) addresses. i.e. 2001:db8:0:1234:0:567:8:1Host Name Host name is a name given to a device on the internet. i.e., a hostname is how a device can be referred to as on the internet (just like the names of a human). Hostnames may be simple names consisting of a single word or phrase, or they may be structured. i.e. LAPTOP-MRRIH5PC The Java.net package provides several useful classes and interfaces to deal with networking and the internet. The IP address and hostname of any local computer can be determined using the java.net.InetAddress class. java.net.InetAddress Java // Java program to determine the IP address // and host name of local computer import java.io.*; import java.net.InetAddress; public class GFG { public static void main(String[] args) throws Exception { // a variable of type InetAddress to store // the address of the local host InetAddress addr = InetAddress.getLocalHost(); // Returns the IP address string in // textual presentation. System.out.println("Local HostAddress: " + addr.getHostAddress()); // Gets the host name for this IP address. System.out.println("Local host name: " + addr.getHostName()); } } OutputLocal HostAddress: 127.0.0.1 Local host name: localhost Comment More infoAdvertise with us Next Article Java program to find IP address of your computer U ushashree Follow Improve Article Tags : Java Technical Scripter Technical Scripter 2020 Practice Tags : Java Similar Reads Java Program to Determine Hostname from IP Address IP Address stands for internet protocol address. It is an identifying number that is associated with a specific computer or computer network. IP addresses are usually written and displayed in human-readable notation such as 192.168.1.35 in IPv4(32-bit IP address). When connected to the internet, the 3 min read Java program to find IP address of your computer An IP(Internet Protocol) address is an identifier assigned to each computer and another device (e.g., router, mobile, etc) connected to a TCP/IP network that is used to locate and identify the node in communication with other nodes on the network. IP addresses are usually written and displayed in hu 2 min read How to Find Your Local IP Address in Debian 11 The IP address is the specific number that identifies the devices on the network. This IP address will help the other devices to find and communicate with your device. When you connect your device to a a computer or phone to the local network such as your home and office network it immediately assig 4 min read Finding IP address of a URL in Java Prerequisite: InetAddressgetByName() : Returns the InetAddress of the given host. If the host is a literal IP address, then only its validity is checked. Fetches public IP Address of the host specified. It takes the host as an argument and returns the corresponding IP address. Examples:Â Input : www 2 min read How to get IP Address of clients machine in PHP ? An IP address is used to provide an identity to a device connected to a network. IP address stands for Internet Protocol address. An IP address allows to track the activities of a user on a website and also allows the location of different devices that are connected to the network to be pinpointed a 2 min read How to determine the user IP address using node.js ? Node.js is an open-source, back-end JavaScript runtime environment that runs on the web engine and executes JavaScript code. There are various platforms such as Windows, Linux, Mac OS Â where Node.js can run. The Domain Name System is a hierarchical and decentralized naming system for computers etc t 2 min read Like