Sajmon

ProxyExample

Aug 15th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. Proxy p = ProxyUtils.getProxy("http://www.google.com", "8080");
  2. Log.i("Proxy", "" + p.address().toString());
  3. ProxyConfiguration pc = ProxySettings.getProxySdk12(getActivity(), NetworkUtils.getWifiConfiguration(getActivity()));
  4. pc.writeConfigurationToDevice();
  5.  
  6. // class ProxyUtils
  7. /**
  8.  *
  9.  * @author Sajmon
  10.  *
  11.  */
  12. public class ProxyUtils {
  13.  
  14.     public static String getHostFromURL(String url) {
  15.         try {
  16.             InetAddress address = InetAddress.getByName(new URL(url).getHost());
  17.             return address.getHostAddress();
  18.         }
  19.         catch (Exception e) {
  20.             e.printStackTrace();
  21.             return null;
  22.         }
  23.     }
  24.    
  25.     public static Proxy getProxy(String url, String port) {
  26.         int proxyPort = Integer.parseInt(port);
  27.         Proxy p = new Proxy(Proxy.Type.HTTP, InetSocketAddress.createUnresolved(getHostFromURL(url), proxyPort));
  28.         return p;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment