java - Checking the type of a web proxy -


how determine whether web proxy ip of type http or socks4/5 java?

thank you.

as mentioned in comments other answer, if know ip address of proxy server , want detect type is, try each proxy type in java until 1 works.

import java.io.ioexception; import java.net.inetsocketaddress; import java.net.proxy; import java.net.socketexception; import java.net.url; import java.net.urlconnection; import java.util.arrays; import java.util.list;  public class proxytest {     public static void main(string... args)     throws ioexception     {         inetsocketaddress proxyaddress = new inetsocketaddress("myproxyaddress", 1234);         proxy.type proxytype = detectproxytype(proxyaddress);         system.out.println(proxyaddress + " " + proxytype + " proxy.");     }      public static proxy.type detectproxytype(inetsocketaddress proxyaddress)     throws ioexception     {         url url = new url("http://www.google.com");         list<proxy.type> proxytypestotry = arrays.aslist(proxy.type.socks, proxy.type.http);          (proxy.type proxytype : proxytypestotry)         {             proxy proxy = new proxy(proxytype, proxyaddress);              //try socks             urlconnection connection = null;             try             {                 connection = url.openconnection(proxy);                  //can modify timeouts if default timeout taking long                 //connection.setconnecttimeout(1000);                 //connection.setreadtimeout(1000);                  connection.getcontent();                  //if here made successful connection                 return(proxytype);             }             catch (socketexception e) //or possibly more generic ioexception?             {                 //proxy connection failed             }         }          //no proxies worked if here         return(null);     } } 

in code, first tries connect www.google.com using proxy @ myproxyaddress socks, , if fails try using http proxy, returning method worked, or null if none worked.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -