updated git and svn scripts
[xrzperl.git] / parse_proxycn
blob2eabadcbf63c5bca1ae94a5dd6ea92a62789ca6a
1 #!/usr/bin/perl -w
2 ###APPNAME: parse_proxycn
3 ###APPAUTHOR: duel
4 ###APPDATE: 2009-01-24 01:42:36
5 ###APPVER: 0.1
6 ###APPDESC: parse_proxycn
7 ###APPUSAGE:
8 ###APPEXAMPLE: parse_proxycn
9 ###APPOPTION:
10 use strict;
12 #ENV variable MUST be defined somewhere,
13 #FOR perl to search modules from,
14 #OR nothing will work
15 use lib $ENV{XR_PERL_MODULE_DIR};
17 use MyPlace::Script::Usage qw/help_required help_even_empty/;
18 exit 0 if(help_required($0,@ARGV));
19 #exit 0 if(help_even_empty($0,@ARGV));
21 my %proxys;
22 my $type;
23 while(<>) {
24 chomp;
25 if(/\<TD class=\"list\"\>\s*(HTTP|SOCKS)\d*\s*\<\/TD\>/i) {
26 $type = $1;
27 $type = "PROXY" if(uc($type) eq "HTTP")
29 if($type) {
30 my @match = $_ =~ /clip\('([\d\.]+:\d+)'\)/g;
31 foreach(@match) {
32 $proxys{"$type $_"}=1;
33 $type = undef;
37 print join("\n",keys %proxys),"\n";
38 exit 0;
39 my @proxys = keys %proxys;
40 my @pac;
41 push @pac,"var count=0;\nvar index=0;\nfunction FindProxyForURL(url, host){";
42 push @pac,"\tvar proxys = new Array();";
43 push @pac,"\tvar proxys_max = $#proxys;";
44 foreach my $idx(0 .. $#proxys) {
45 push @pac, "\tproxys[" . $idx . "]=\"" . $proxys[$idx] . "\"";
47 push @pac,"\tcount++;\n\tif(count>3){count=0;index++;}\n\tif(index>proxys_max){index=0;}}";
48 push @pac,"\treturn proxys[index];";
49 push @pac,"}";
51 print join("\n",@pac),"\n";