Start New Discussion within our Software Development Community

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.

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

C:\ cannot find symbol
symbol : class HttpURLConnection
location: class GetIP Conn = (HttpURLConnection)URL.openConnection();
C:\ cannot find symbol
symbol : method readline()
location: class
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 javax.swing.JOptionPane;
public class GetIP {

    public GetIP() {

         public static void main(String args[]) {
  URL = new""); Conn = (HttpURLConnection)URL.openConnection(); InStream = Conn.getInputStream(); Isr = new; Br = new;
		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 Conn = (HttpURLConnection)URL.openConnection();
Conn.setReadTimeout(2000); // 2,000 miliiseconds InStream = Conn.getInputStream();
// etc
This question has already been answered. Start a new discussion instead.