In this example, we will take a look at the Java code to get the IP address of the Client computer where this code is executed,
We can make use of the getLocalHost() method from InetAddress class that is present in java.net package.
Example: Code to get the IP Addressimport java.net.InetAddress;
import java.net.UnknownHostException;
/**
* Java Program to identify local
* IP address
*
* Author: Code2care.org
* Date: 03-Apr-2022
* Version: 1.0
*
*/
public class JavaGetIPAddressExample {
public static void main(String[] args) throws UnknownHostException {
System.out.println(getLocalIPAddress());
}
public static String getLocalIPAddress() throws UnknownHostException {
InetAddress ipAddress =InetAddress.getLocalHost();
String ipAddressString = ipAddress.getHostAddress();
return ipAddressString;
}
}
Output:
192.168.0.122
More Posts related to Java,
- How to install Java 11 on Mac
- Get Client IP address from HTTP Response in Java
- SharePoint Open in the client application document opens in browser
- How to verify if java is installed on the computer and get version detail
- Java - Check if array contains the value
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- How to run Java Unit Test cases with Apache Maven?
- What Java version is used for Minecraft 1.18
- List of jar files for Jax-ws (SOAP) based Java Web Services
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- Convert Instant timestamp into LocalDateTime Java Code Example
- Java - Calculate time taken for the code to execute in milliseconds or nanoseconds
- Create simple struts2 project using maven commands
- Java - PatternSyntaxException
- List of Online Java compiler with console
- Minecraft Java Edition
- How to declare and initialize Array in Java Programming
- [Solved] com.sun.xml.ws.transport.http.servlet.WSServletContextListener ClassNotFoundException
- Java XML-RPC 3.1.x based web service example
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server
- Java 8 foreach loop code examples
- Java -Day of the week using Java 8 DayOfWeek Enum
- Java 8 - Convert List to Map Examples
- Java: TimeZone List with GMT/UTC Offset
- list of jars required for hibernate 4.x.x
More Posts:
- Add Buttons at the bottom of Android Layout xml file - Android
- How to wrap column text in SharePoint Online Modern List Grid View using JSON formatting - SharePoint
- List of 60 useful FTP Client Commands to access server - FTP
- Eclipse : Workspace was written with an older version of the product and will be updated - Eclipse
- Struts 2 : There is no Action mapped for namespace [/] and action name [form] associated with context path [/proj] - Java
- Toast not getting displayed Android App - Android
- No Android device found : Android File Transfer App Mac OS X - Android
- NOTE: This project contains resource errors, so aapt did not succeed, which can cause rendering failures. Fix resource problems first. - Android