$context
=~ s/^\s*\n//mg;
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
my $file =
"blacklist.txt";
open(FILEIP, $file); while($var=<FILEIP>) { chomp $var; # 去除换行 if($var=~/^\s*(\S+)\s*$/) { $var=$1 # 去除左右空格 } print "-$var-\n"; #加些边界特殊字符打印,才能看出是否包含空格等字符 if($site_name =~ /$var/) { print "match it...\n"; last; } } |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
sub HttpHeadrParse
#解析http头部信息 { my $header = shift; # $header =~s/\r\n/$~/g; my @element = split(/\r\n/,$header); my %hash; my $key = ""; my $var = ""; my @tmp= ""; foreach $var (@element) { if($var=~/POST./ or $var =~/GET./) { @tmp = split(/ /,$var); $hash{ "Method"} = $tmp[ 0]; $hash{ "Cgi"} =$tmp[ 1]; # print "method : $tmp[0] cgi: $tmp[1]\n"; $hash{ "Protocol"} =$tmp[ 2]; } else { @tmp = split(/:/,$var); $hash{$tmp[ 0]}=$tmp[ 1]; if($tmp[ 0] eq "Host") { if($tmp[ 2] eq "") { $hash[ "Port"] = "80"; } else { $hash[ "Port"] = $tmp[ 2]; } } } } return %hash; } |
1
2 3 4 5 6 7 |
sub trim
{ my $string = shift; $string =~ s/^\s+//; $string =~ s/\s+$//; return $string; } |
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#输入name,value字符串,name界定符;返回唯一的name列表 sub get_name{ my $param = shift; my $delim = shift; return '' if ! defined($param) || $param eq ''; my @name_value = split( "$delim", $param); my %hash_name_value = (); for( my $i = 0; $i<= $ #name_value; $i++){ my $name = ''; my $value = ''; if($name_value[$i] =~ /([^=]+)=(.*)/){ $name = $1; $value = $2; } if($name =~ /[.\d]{ 10, 50}|1\d{ 9, 9}$/){ #去除随机数name next; } $hash_name_value{ "$name"} = $value; } my @names = sort keys %hash_name_value; my $names_str = join( "$delim",@names); return $names_str; } #计算uniquemd5 sub uniquemd5{ my ($url, $params, $query_get, $query_post) = @_; my $uniquemd5_str = $url; my $port = 0; my $q_get_name = ''; my $q_post_name = ''; my $p_name = ''; $q_get_name = get_name($query_get, '&'); $q_post_name = get_name($query_post, '&'); $p_name = get_name($params, ';'); if($url =~ m/(?:http|https):\/\/[^:\/;? #]+(?::([0-9]+))?/){ $port = $1; } if( defined $port && 80 == $port){ $uniquemd5_str =~ s/:[ 0- 9]+//; } $uniquemd5_str .= ",$p_name,$q_get_name,$q_post_name"; my $md5 = Digest::MD5->new; my $uniquemd5 = $md5->add($uniquemd5_str)->hexdigest; return $uniquemd5; } |