Java Socket to find real client IP Address
<p>I am trying to get Real Client IP address using a Java applet. I want to eventually use it in a PHP script, to help with security and authentication. None of the PHP methods will work as the various HTTP headers are not available and can be spoofed easily.</p>

<p>So I am adopting the method suggested in <a href="http://stackoverflow.com/questions/1510526/get-the-correct-local-ip-adress-from-java-applet">Get the correct local IP adress from java applet</a> and <a href="http://www.jguru.com/faq/view.jsp?EID=15832" rel="nofollow">http://www.jguru.com/faq/view.jsp?EID=15832</a></p>

<p>However, I cannot compile my simple Applet. I am new to Java, so am a little confused.</p>

<p>Code is:</p>

<pre><code>import java.net.*;
import java.io.*;

public class SimpleSocketClient
{
    public SimpleSocketClient()
    {
        try
        {
            Socket socket = new Socket("89.185.150.131", 80);
        }
        catch(Exception exc)
        {
            System.out.println("Error in initialising the network - " + exc.toString());
        }

        InetAddress addr = socket.getLocalAddress();
        String hostAddr = addr.getHostAddress();
        System.out.println("Addr: " + hostAddr);

    }

}
</code></pre>

<p>When compiling, I get the following error:</p>

<pre><code>C:\mba&gt;javac SimpleSocketClient.java
SimpleSocketClient.java:18: cannot find symbol
symbol  : variable socket
location: class SimpleSocketClient
        InetAddress addr = socket.getLocalAddress();
                           ^
1 error

C:\mba&gt;
</code></pre>

<p>Thanks</p>
