Hello friends,
I am having a small problem, i have already designed a chat application, the chat works fine over a local network but now I want to use it over the internet. Logically the program should but what happened is that to get the IP I have used

clientInformation.clientIPAddress = clientsoc.getInetAddress().getHostAddress();

and it gives only the local and I want the public IP of that machine. Can someone help me please.

I just want to get the external IP in a textbox!!

Thanks a lot in advance for your help.

Recommended Answers

All 6 Replies

Hello, thanks for the link, I have tried to run the code but I've got the following error:

C:\GetIP.java:8: cannot find symbol
symbol : class HttpURLConnection
location: class GetIP
java.net.HttpURLConnection Conn = (HttpURLConnection)URL.openConnection();
C:\GetIP.java:17: cannot find symbol
symbol : method readline()
location: class java.io.BufferedReader
System.out.print("Your IP address is " + Br.readline());
2 errors

Process completed.

Thanks a lot for the answer.

I've modified the code and no more errors, but still I didn't get the IP, the program keeps running and nothing appears.

import java.net.*;
import java.io.*;
import javax.swing.JOptionPane;
public class GetIP {

    public GetIP() {

         public static void main(String args[]) {
    	java.net.URL URL = new java.net.URL("http://www.whatismyip.org/");
		java.net.HttpURLConnection Conn = (HttpURLConnection)URL.openConnection();
		java.io.InputStream InStream = Conn.getInputStream();
		java.io.InputStreamReader Isr = new java.io.InputStreamReader(InStream);
		java.io.BufferedReader Br = new java.io.BufferedReader(Isr);
		System.out.print("Your IP address is " + Br.readLine());
		JOptionPane.showMessageDialog(null, "IP is: " + Br.readLine() );
    	}catch(Exception e){e.printStackTrace();}

I've not tried this myself, but the API doc implies you should be able to

java.net.HttpURLConnection Conn = (HttpURLConnection)URL.openConnection();
Conn.setReadTimeout(2000); // 2,000 miliiseconds 
java.io.InputStream InStream = Conn.getInputStream();
// etc

we want the if any one login then that system address.
how to get please help me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.