File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Iterator ;
2+ import java .util .List ;
3+
4+ import java .net .InetSocketAddress ;
5+ import java .net .Proxy ;
6+ import java .net .ProxySelector ;
7+ import java .net .URI ;
8+
9+ public class SystemProxySettings {
10+ public static void main (String [] args ) {
11+ try {
12+ System .setProperty ("java.net.useSystemProxies" , "true" );
13+ List <Proxy > l = ProxySelector .getDefault ().select (
14+ new URI ("http://www.example.com/" ));
15+
16+ for (Iterator <Proxy > iterate = l .iterator (); iterate .hasNext ();) {
17+ Proxy newProxy = iterate .next ();
18+ System .out .println ("Proxy Hostname is: " + newProxy .type ());
19+ InetSocketAddress socketAddr = (InetSocketAddress ) newProxy .address ();
20+
21+ if (socketAddr == null ) {
22+ System .out .println ("No available proxy to report..." );
23+ } else {
24+ System .out .println ("Proxy System Hostname is: " + socketAddr .getHostName ());
25+ System .out .println ("Proxy System Port is: " + socketAddr .getPort ());
26+ }
27+ }
28+ } catch (Exception e ) {
29+ e .printStackTrace ();
30+ }
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments