Getting Your Own Device IP Address using Java Last Updated : 08 Jun, 2022 Summarize Comments Improve Suggest changes Share Like Article Like Report An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication. An IP address serves two principal functions: host or network interface identification and location addressing. There are two versions of internet protocol addresses which are named as follows: IPv4IPv6 An IPv4 Addresses consists of 32 bits which limit the address space to 4294967296 (232) possible unique addresses. IPv4 reserves some addresses for special purposes such as private networks (~18 million addresses) or multicast addresses (~270 million addresses). The rapid exhaustion of IPv4 address space prompted the Internet Engineering Task Force to explore new technologies to expand the addressing capability on the Internet. This new generation of Internet Protocol was eventually named Internet Protocol Version 6 (IPv6) in 1995. The address size was increased from 32 to 128 bits (16 octets), thus providing up to 2128 (approximately 3.403×1038) addresses. Implementation: Pseudo-code is as follows: InetAddress myIP = InetAddress.getLocalHost(); System.out.println(myIP.getHostAddress()); Example Java // Java Program to Find IP address of Own Device // Importing input output class import java.io.*; // Importing InetAddress class from java.net package import java.net.InetAddress; // Main class public class GFG { // Main driver method public static void main(String[] args) { // Try block to check for exceptions try { // Creating an object of InetAddress class to // get the Ip address InetAddress myIP = InetAddress.getLocalHost(); // Display message only System.out.println("My IP Address is : "); // Print and display the IP address System.out.println(myIP.getHostAddress()); } // Catch block to handle the exceptions catch (Exception e) { // Display message to be printed on console // as the exception occurs System.out.println("Some Error Occurred"); } } } OutputMy IP Address is: 127.0.0.1 Comment More infoAdvertise with us Next Article How to implement a Simple DNS Resolver in Java? Y yogeshsherawat77 Follow Improve Article Tags : Java Java Programs Practice Tags : Java Similar Reads Java Program to Get System IP Address in Windows and Linux Machine IP Address: An Internet Protocol address is a numerical label assigned to each device connected to a computer network that uses the Internet Protocol for communication. Packages used: io (input-output): This package provides for system input and output through data streams, serialization, and the fi 2 min read Extracting IP Address From a Given String Using Regular Expressions Prerequisites: Regular ExpressionsIP addressGiven a string str, the task is to extract all the IP addresses from the given string. Let us see how to extract IP addresses from a file. Input: str="The IPV4 address of Port A is: 257.120.223.13. And the IPV6 address is:fffe:3465:efab:23fe:2235:6565:aaab 4 min read Program to convert IP address to hexadecimal Given an IP Address and task is to change the IP address equivalent to the hexadecimal value. Examples: Input : 127.0.0.1Output : 0x7f000001Input : 172.31.0.2Output : 0xac1f0002Explanation: Using the Library function to convert the IP address into the hexadecimal value we use the " arpa/inet.h " hea 4 min read Convert a String to an InetAddress in Java InetAddress is one of the Java classes which is available in java.net package. The InetAddress class contains a lot of built-in methods for handling networking-related functions in Java. In our case we need to convert a String to an InetAddress means IP Address. Normally an IP Address format looks l 4 min read How to implement a Simple DNS Resolver in Java? DNS stands for Domain Name System. For the implementation of the simple DNS resolver in Java is allowed to translate the domain names into the corresponding IP addresses in the programmatically. Domain Name System (DNS) plays a crucial component of internet communication and translates human-readabl 3 min read Java Networking Programs - Basic to Advanced Java allows developers to create applications that can communicate over networks, connecting devices and systems together. Whether you're learning about basic connections or diving into more advanced topics like client-server applications, Java provides the tools and libraries you need. This Java Ne 3 min read Like