Chinaunix首页 | 论坛 | 博客
  • 博客访问: 259498
  • 博文数量: 74
  • 博客积分: 1470
  • 博客等级: 上尉
  • 技术积分: 793
  • 用 户 组: 普通用户
  • 注册时间: 2008-11-25 21:01
文章分类

全部博文(74)

文章存档

2011年(1)

2010年(32)

2009年(32)

2008年(9)

我的朋友

分类: LINUX

2009-09-17 22:18:08

这个脚本的功能是从工大匹配出ip/mask序列对.如以下形式:
12.18.186.1/255.255.255.2
12.130.28.2/255.255.255.2
12.154.67.1/255.255.255.1
38.100.138.1/255.255.255.2
58.17.0.0/255.255.0.0
58.18.0.0/255.254.0.0
.......

初学shell编程,仅仅作为纪念

#!/bin/sh
source_file=/tmp/iplist.htm
tmp_file=/tmp/tmpfile.txt
ip_file=/tmp/ip.txt
ip_mask_file=/tmp/ip_mask.txt
n=0

echo -n "" > $ip_file
echo -n "" > $ip_mask_file
wget -O $source_file http://hitsun.hit.edu.cn/zxiplist.htm

echo "Start to analyse the source file..."

sed -n 's/\([0-9]*\.[0-9]*\.[0-9]*\.[0-9]\)/$\1$/p' $source_file | cut -d$ -f2 > $tmp_file
cat $tmp_file | while read ip
do
    tmp=$(expr $n % 3)
    if [ $tmp -eq 0 ]; then
        echo $ip >> $ip_file
        ip_bak=$ip
    fi
    if [ $tmp -eq 2 ]; then
        ip_bak=$ip_bak"/"$ip
        echo $ip_bak >> $ip_mask_file
    fi
    
    n=$(expr $n + 1)
done
echo "Done"

阅读(2166) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~