
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java program to find IP Address of the client
To find the IP Address of the client, the Java code is as follows −
Example
import java.net.*; import java.io.*; import java.util.*; import java.net.InetAddress; public class Demo{ public static void main(String args[]) throws Exception{ InetAddress my_localhost = InetAddress.getLocalHost(); System.out.println("The IP Address of client is : " + (my_localhost.getHostAddress()).trim()); String my_system_address = ""; try{ URL my_url = new URL("http://bot.whatismyipaddress.com"); BufferedReader my_br = new BufferedReader(new InputStreamReader(my_url.openStream())); my_system_address = my_br.readLine().trim(); } catch (Exception e){ my_system_address = "Cannot Execute Properly"; } } }
Output
The IP Address of client is : 127.0.0.1
A class named Demo contains the main function. In this main function, an instance of the InetAddress class is created and the ‘getHostAddress’ function is used to get the IP address of the client. This is displayed on the console.
- Related Articles
- C# program to find IP Address of the client
- Python program to find the IP Address of the client
- Java program to Get IP address of the system
- Java program to display Hostname and IP address
- Java program to convert Byte array to IP Address
- C Program to find IP Address, Subnet Mask & Default Gateway
- C Program to validate an IP address
- JavaScript program to retrieve clients IP address
- Program to find all possible IP address after restoration in C++
- How can we get the client's IP address in ASP.NET MVC C#?
- Program to display hostname and IP address C
- Python program to Display Hostname and IP address?
- C# program to Display Hostname and IP address
- C Program to display hostname and IP address
- Difference between Static IP Address and Dynamic IP Address

Advertisements