summaryrefslogtreecommitdiff
path: root/src/se/leap/openvpn/ProxyDetection.java
diff options
context:
space:
mode:
authorSean Leonard <meanderingcode@aetherislands.net>2013-01-22 22:26:08 -0700
committerSean Leonard <meanderingcode@aetherislands.net>2013-01-22 22:26:08 -0700
commit2bb6e8c9a956c56658807c7f2d25ab850243bbe6 (patch)
tree9e3a2e318d0503b33d94514836b8a9bc2db8aaa6 /src/se/leap/openvpn/ProxyDetection.java
parent613543d9c00e607f25e7f745a60fb4e3ec3b5148 (diff)
Start rebranding: a whole lotta string replacement, moving src/ file tree
Diffstat (limited to 'src/se/leap/openvpn/ProxyDetection.java')
-rw-r--r--src/se/leap/openvpn/ProxyDetection.java53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/se/leap/openvpn/ProxyDetection.java b/src/se/leap/openvpn/ProxyDetection.java
new file mode 100644
index 00000000..7114857d
--- /dev/null
+++ b/src/se/leap/openvpn/ProxyDetection.java
@@ -0,0 +1,53 @@
+package se.leap.openvpn;
+
+import java.net.InetSocketAddress;
+import java.net.MalformedURLException;
+import java.net.Proxy;
+import java.net.ProxySelector;
+import java.net.SocketAddress;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.List;
+import se.leap.leapclient.R;
+
+public class ProxyDetection {
+ static SocketAddress detectProxy(VpnProfile vp) {
+ // Construct a new url with https as protocol
+ try {
+ URL url = new URL(String.format("https://%s:%s",vp.mServerName,vp.mServerPort));
+ Proxy proxy = getFirstProxy(url);
+
+ if(proxy==null)
+ return null;
+ SocketAddress addr = proxy.address();
+ if (addr instanceof InetSocketAddress) {
+ return addr;
+ }
+
+ } catch (MalformedURLException e) {
+ OpenVPN.logError(R.string.getproxy_error,e.getLocalizedMessage());
+ } catch (URISyntaxException e) {
+ OpenVPN.logError(R.string.getproxy_error,e.getLocalizedMessage());
+ }
+ return null;
+ }
+
+ static Proxy getFirstProxy(URL url) throws URISyntaxException {
+ System.setProperty("java.net.useSystemProxies", "true");
+
+ List<Proxy> proxylist = ProxySelector.getDefault().select(url.toURI());
+
+
+ if (proxylist != null) {
+ for (Proxy proxy: proxylist) {
+ SocketAddress addr = proxy.address();
+
+ if (addr != null) {
+ return proxy;
+ }
+ }
+
+ }
+ return null;
+ }
+} \ No newline at end of file