Java program to find IP address of your computer Last Updated : 09 Nov, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 human-readable notation such as 192.168.1.35 in IPv4(32-bit IP address). An IP address serves two principal functions: host or network interface identification and local addressing. Its role has been characterized as follows: "A name indicates what we seek. An address indicates where it is. A route indicates how to get there." Prerequisites : Networking in Java | Set 1 (InetAddress class), trim() in Java.InetAddress.getLocalHost() is used to find the private IP addresses used in LAN or any other local network. To find public IP, we use http://bot.whatismyipaddress.com (An online utility to find your public IP), we open the URL, read a line and print the line. Below is the Java implementation of the above steps. Java // Java program to find IP address of your computer // java.net.InetAddress class provides method to get // IP of any host name import java.net.*; import java.io.*; import java.util.*; import java.net.InetAddress; public class JavaProgram { public static void main(String args[]) throws Exception { // Returns the instance of InetAddress containing // local host name and address InetAddress localhost = InetAddress.getLocalHost(); System.out.println("System IP Address : " + (localhost.getHostAddress()).trim()); // Find public IP address String systemipaddress = ""; try { URL url_name = new URL("http://bot.whatismyipaddress.com"); BufferedReader sc = new BufferedReader(new InputStreamReader(url_name.openStream())); // reads system IPAddress systemipaddress = sc.readLine().trim(); } catch (Exception e) { systemipaddress = "Cannot Execute Properly"; } System.out.println("Public IP Address: " + systemipaddress +"\n"); } } Output: System IP Address : 10.0.8.204 Public IP Address : 35.166.48.97 Note: The above output is for a machine that is used by GeeksforGeeks online compiler, ide.geeksforgeeks.org Comment More infoAdvertise with us Next Article Java Program to Determine Hostname from IP Address K kartik Improve Article Tags : Java 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 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 Determining the IP Address & Hostname of Local Computer in Java 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 provi 3 min read Pinging an IP Address in Java | Set 1 PING stands for Packet InterNet Groper in the computer networking field. It's a computer network administration software used to test the reachability of a host on an Internet Protocol (IP) network. It measures the round-trip time for messages sent from the originating host to a destination computer 3 min read Pinging an IP address in Java | Set 2 (By creating sub-process) In article Pinging an IP address in Java, we have discussed how to ping an IP address using java.net.InetAddress.isReachable() method. In this post we will discuss how to execute ping command by creating a sub-process. Prerequisite : ProcessBuilder class , Process classBelow Java program creates a m 3 min read Internet Address Resolution in Java Internet-Address resolution is the process of converting a domain name (like www.geeksforgeeks.org) to an IP address or vice versa. This is the first step in connecting to a network. Network devices talk to each other using IP addresses, but people tend to remember domain names better. Most of the t 4 min read Like