Skip to content

Commit 6b0ba17

Browse files
Initial code upload.
1 parent 221bc32 commit 6b0ba17

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

scripts/SystemProxySettings.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)