3

i checked this page and got some usefull code for using a proxy in java code when connecting to a webpage.

I can confirm that pages like whatsmyip do indeed tell me that proxy is working - it is showing proxy ip. The problem is that the page i am accesing to in java code, somehow detects my true ip and blocks content. I do know how it does that (header, return ip, etc.), what i do not know is how to bypass that.

Maybe another interesting thing is that this page works with no problems using 1 of the best known online proxy sites - it shows content. Now what is even more interesting is that i tried taking that sites ip and used it as proxy in my program, but there it didn't work - true ip got detected, which is really strange.

edit: This is my new code:

System.setProperty("java.net.useSystemProxies","false");
    System.setProperty("http.proxyHost", "94.230.208.147");                                      
    System.setProperty("http.proxyPort", "9001");   
    System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1");    

    System.setProperty("https.proxyHost", "94.230.208.147");                                      
    System.setProperty("https.proxyPort", "9001");   
    System.setProperty("https.nonProxyHosts", "localhost|127.0.0.1");

I can confirm that https://whatsmyip.com/ isn't fooled by this proxy and can see my true ip. What did i forget to include ?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Jessica
  • 49
  • 4
  • 1
    Why do you think it's detecting your true IP as opposed to detecting that you're using a proxy? – shmosel Oct 31 '18 at 00:02
  • I know it is detecting my true IP because it denies content of this page. – Jessica Oct 31 '18 at 01:02
  • Maybe that's because it detects you're using a proxy. – shmosel Oct 31 '18 at 01:06
  • And how do i make sure it doesnt detect i am using a proxy ? – Jessica Oct 31 '18 at 01:15
  • Who said you can? – shmosel Oct 31 '18 at 01:15
  • Well i am asking. And why doesnt it detect proxy when i use online proxy to access the page .. – Jessica Oct 31 '18 at 12:47
  • 1
    This page has a ton of excellent information in it [how do i set the proxy to be used by the jvm](https://stackoverflow.com/questions/120797/how-do-i-set-the-proxy-to-be-used-by-the-jvm) but doing this `System.setProperty("java.net.useSystemProxies","true");` seems like it would negate the next two lines, instead you'd want `System.setProperty("java.net.useSystemProxies","false");` also don't forget there is https and http settings! – JGlass Oct 31 '18 at 20:19
  • Thank you for your reply ! I edited my original message with new code - i am accesing a https page, i tried it on https://whatsmyip.com/ and it can see my real ip - proxy settings arent working. – Jessica Nov 02 '18 at 01:23
  • I tested again with some other proxy and it is working. Thank you JGlass, you are a gentleman, bless you ! – Jessica Nov 02 '18 at 01:40

1 Answers1

1

Add this at the end of your code:

System.setProperty("http.nonProxyHosts", "localhost|127.0.0.1");

That indicates the hosts that should be accessed without going through the proxy. Typically this defines internal hosts. The value of this property is a list of hosts, separated by the '|' character.

Jonathan Gagne
  • 4,241
  • 5
  • 18
  • 30
  • Correct. The original question has the wrong property name: `"https.nonProxyHosts"` Drop the `s` from `https` – toddcscar Apr 27 '20 at 16:42