When I run the following code I expect it to display:
where aaa.bbb.ccc.ddd is my real IP. This does not happen, it instead displays:194.36.10.154
aaa.bbb.ccc.ddd
when I uncomment the pause, the code performs as expected. Is there something going on behind the scenes causing this or is it a bug in java?194.36.10.154
194.36.10.154
Code:import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.InetSocketAddress; import java.net.Proxy; import java.net.SocketAddress; import java.net.URL; import java.net.URLConnection; public class ProxyTest { public static void test1() { String socks_server_proxy = "194.36.10.154"; int socks_port = 3128; try { SocketAddress addr = new InetSocketAddress(socks_server_proxy, socks_port); Proxy proxy = new Proxy(Proxy.Type.HTTP, addr); URL url = new URL("http://312c.info/ip.php"); URLConnection conn = url.openConnection(proxy); BufferedReader in = new BufferedReader(new InputStreamReader(conn .getInputStream())); String line; while ((line = in.readLine()) != null) { System.out.println(line); } in.close(); } catch (Exception e) { e.printStackTrace(); } } public static void test2() { try { URL url2 = new URL("http://312c.info/ip.php"); URLConnection conn2 = url2.openConnection(Proxy.NO_PROXY); BufferedReader in2 = new BufferedReader(new InputStreamReader(conn2 .getInputStream())); String line2; while ((line2 = in2.readLine()) != null) { System.out.println(line2); } in2.close(); } catch (Exception e) { e.printStackTrace(); } public static void p(Object[] s) { for (int i = 0; i < s.length; i++) if (s[i] != null) System.out.println(s[i].toString()); else System.out.println("null"); } public static void main(String[] args) { test1(); // try { // Thread.sleep(5000); // } catch (InterruptedException e) { // e.printStackTrace(); // } test2(); }


Reply With Quote


Bookmarks