Created
September 11, 2013 14:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compiling:
Running with no proxy:
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.