Skip to content

Instantly share code, notes, and snippets.

@itsPG
Created August 26, 2013 18:40
Show Gist options
  • Save itsPG/6344952 to your computer and use it in GitHub Desktop.
Save itsPG/6344952 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
open(fin,"/var/log/PG_err_try.log");
@q = <fin>;
my %table;
for(@q)
{
if($_ =~ /Ban ([0-9\.]+)/)
{
$table{$1}++;
}
if($_ =~ /Unlock ([0-9\.]+)/)
{
$table{$1}=$table{$1}-100;
}
}
my %table2;
while (my($key,$value) = each(%table))
{
if($value>1)
{
$table2{$key}=$value;
}
}
#my @list = sort { $table2{$b} <=> $table2{$a} } keys %table2;
sub ipsort {
my ($a1, $a2, $a3, $a4) = $a =~ /(\d+).(\d+).(\d+).(\d+)/; # 分為四個數字
my ($b1, $b2, $b3, $b4) = $b =~ /(\d+).(\d+).(\d+).(\d+)/;
$table2{$b} <=> $table2{$a} or $a1 <=> $b1 or $a2 <=> $b2 or $a3 <=> $b3 or $a4 <=> $b4; # 進行多子鍵排序
}
my @list = sort ipsort keys %table2;
open fn,">/home/PG/public_html/ban_list.html";
print fn "<h1> 嘗試攻擊IP列表 </h1>\n";
print fn "<h2>以下是曾經攻擊過miko.tw ssh的主機列表 </h2>\n";
print fn "<h2>若您未曾攻擊過本主機而出現在這張表上, 有可能您使用著浮動ip區段 , 或者是電腦曾經中毒</h2>\n";
print fn "Last Update ".`date`."<br/>";
for(@list)
{
if($table2{$_}>=10)
{
print fn "<font size=72 color=red>$_ / times:$table2{$_}</font><br/>\n";
}
elsif($table2{$_}>=5)
{
print fn "<font size=36 color=red>$_ / times:$table2{$_}</font><br/>\n";
}
elsif($table2{$_}>1)
{
print fn "$_ / times:$table2{$_}<br/>\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment