5 * License: LGPL 2.1+ with static linking exception
17 #include "../rocksock.h"
20 static char chk_host
[512];
21 static int chk_host_port
;
23 static int scanHost(char* baseproxy
, char* scanproxy
) {
30 rocksock_init(soc
, proxies
);
31 rocksock_set_timeout(soc
, timeout
);
33 if(rocksock_add_proxy_fromstring(soc
, baseproxy
))
35 if(rocksock_add_proxy_fromstring(soc
, scanproxy
))
38 if (!rocksock_connect(soc
, chk_host
, chk_host_port
, 0)){
39 ret
= 0; /* success */
41 //printf("%s\n", soc->lasterror.errormsg);
45 rocksock_disconnect(soc
);
51 static int usage(const char *argv0
) {
55 "[-b type://[user:pass@]base_proxy_ip:port]\n"
57 "[-c check_ip:port]\n"
58 "[-T timeout_in_millisec]\n"
60 "read [type://]ips:port from STDIN\n"
61 "if type is given, all ip:port tuples from STDIN won't need a prefix\n"
62 "if base proxy is given, it will be used as first proxy\n"
63 "timeout defaults to 1500.\n"
64 "checkip:port defaults to cnn.com:80\n"
65 "for every proxy that works, its address will be echoed to stdout\n"
66 "exit code is 0 when last proxy worked\n\n"
67 "example: echo 127.0.0.1:9050 | %s -t socks4 -T 2000\n"
68 "example: echo socks5://user:pass@127.0.0.1:1080 | %s\n"
69 "\nyou may want to use JOBFLOW or GNU parallel for speedy parallel checks\n"
70 , argv0
, argv0
, argv0
);
74 int main(int argc
, char** argv
) {
78 char *checkurl
= "cnn.com:80";
81 while ((c
= getopt(argc
, argv
, "c:T:b:t:")) != -1) {
87 timeout
= atoi(optarg
);
90 if(!strcmp(optarg
, "socks4")) ;
91 else if(!strcmp(optarg
, "socks5")) ;
92 else if(!strcmp(optarg
, "http")) ;
94 dprintf(2, "invalid proxy type\n");
103 return usage(argv
[0]);
108 char *p
= strchr(checkurl
, ':');
109 if(!p
) return usage(argv
[0]);
111 size_t l
= p
-checkurl
;
112 strncpy(chk_host
, checkurl
, l
);
114 chk_host_port
= atoi(++p
);
119 while(fgets(buf
, sizeof buf
, stdin
)) {
120 char nb
[1024+10], *p
;
121 if((p
= strrchr(buf
, '\n')))
123 if(*buf
== 0 || *buf
== '#') continue;
124 snprintf(nb
, sizeof nb
, "%s%s%s",
125 typestring
? typestring
: "",
126 typestring
? "://" : "",
128 if(0 == (ret
= scanHost(baseproxy
, nb
)))