扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
问题
描述:用于Linux环境下,针对netstat指令Foreign Address统计结果分析工具
用途:日常Tech技术服务中,对于某客户服务器的特定外来IP访问次数统计的快速查阅
需求:来自Oscar(Tech) 2005.05.15提出
解决方案
touch /foreign_address_statistic_run.sh
chmod 755 /foreign_address_statistic_run.sh
cat /foreign_address_statistic_run.sh
# Author: Stoneshen
# Latest Updating Date: 2006.5.15
# Utility Usage: . /foreign_address_statistic_run.sh
rm -f /netstat-na_foreign_address_list
netstat -na|grep :|awk '{print $5}' >/netstat-na_foreign_address_list
rm -rf /foreign_address_accessing_statistic.txt
/usr/bin/perl /foreign_address_statistic.pl
---
touch /foreign_address_statistic.pl
chmod 755 foreign_address_statistic.pl
cat /foreign_address_statistic.pl
#!/usr/bin/perl
# Author: Stoneshen
# Latest Updating Date: 2006.5.15
# Utility Usage: /usr/bin/perl /foreign_address_statistic.pl
$total=0;
$logfile="/netstat-na_foreign_address_list";
open(FILE,$logfile);
while($line=
{
if ($line=~/(.+)\.(.+)\.(.+)\.(.+)\:/){
$cureip=$1.".".$2.".".$3.".".$4;
print $cureip."\n";
$total++;
if (defined($iplist{$cureip})){
$iplist{$cureip}=$iplist{$cureip}+1;
}else{
$iplist{$cureip}=1;
}
}
}
close(FILE);
`date >>/foreign_address_accessing_statistic.txt`;
open(FOREIGNADDRESSLIST,">> /foreign_address_accessing_statistic.txt");
foreach $key(keys %iplist){
if ($iplist{$key}>0){
# You could control the limitation of the statistic, default including all Foreign IPs
print FOREIGNADDRESSLIST $key." ".$iplist{$key}."\n";
}
}
---
# cat /netstat-na_foreign_address_list
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
192.168.7.5:1374
192.168.7.5:1236
192.168.7.5:1245
0.0.0.0:*
0.0.0.0:*
0.0.0.0:*
# cat /foreign_address_accessing_statistic.txt
一 5月 15 14:20:09 CST 2006
0.0.0.0 16
192.168.7.5 3
END
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者