Skip to content

Instantly share code, notes, and snippets.

@AlainODea
Created September 11, 2013 14:18
Show Gist options
  • Save AlainODea/6524270 to your computer and use it in GitHub Desktop.
Save AlainODea/6524270 to your computer and use it in GitHub Desktop.
Java Proxy Verification - Output current proxy in use for a supplied URL (if any) with no dependencies outside JavaSE
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.URI;
public class WhatIsMyProxy
{
public static void main(String[] args)
{
String website = args[0];
Proxy proxy = ProxySelector.getDefault().select(URI.create(website)).iterator().next();
System.out.format("proxy.address=%s%nproxy.type.name=%s%n", proxy.address(), proxy.type().name());
}
}
@AlainODea
Copy link
Author

Compiling:

javac WhatIsMyProxy.java

Running with no proxy:

$ java WhatIsMyProxy https://example.com/
proxy.address=null
proxy.type.name=DIRECT

Running with system proxies:

> java -Djava.net.useSystemProxies=true WhatIsMyProxy https://example.com/
proxy.address=localhost:3128
proxy.type.name=HTTP

Running with an explicit HTTP proxy:

> java -Dhttps.proxyHost=localhost -Dhttps.proxyPort=3128 WhatIsMyProxy https://example.com/
proxy.address=localhost:3128
proxy.type.name=HTTP

Running with an explicit SOCKS proxy:

> java -DsocksProxyHost=localhost -DsocksProxyPort=3128 WhatIsMyProxy https://example.com/
proxy.address=localhost:3128
proxy.type.name=SOCKS

Read more Proxies - Networking Properties on Oracle's documentation site.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment