手机
当前位置:查字典教程网 >脚本专栏 >linuxshell >Shell脚本获取国内各大运营商网段脚本分享
Shell脚本获取国内各大运营商网段脚本分享
摘要:亚太地区网络信息记录在这里,每天都有更新。http://ftp.apnic.net/apnic/stats/apnic/delegated-...

亚太地区网络信息记录在这里,每天都有更新。

http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest

下面这个脚本将对这段文本进行编辑,输出国内几大运营商网段。

复制代码 代码如下:

#!/bin/sh

#auto get the IP Table

#get the newest delegated-apnic-latest

rm delegated-apnic-latest

if type wget

then wget http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest

else fetch http://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest

fi

grep 'apnic|CN|ipv4' delegated-apnic-latest | cut -f 4,5 -d '|' | tr '|' ' ' | while read ip cnt

do

mask=$(bc <<END | tail -1

pow=32;

define log2(x) {

if (x<=1) return (pow);

pow--;

return(log2(x/2));

}

log2($cnt);

END

)

echo $ip/$mask';'>>cnnet

resultext=`whois $ip@whois.apnic.net | grep -e ^netname -e ^descr -e ^role -e ^mnt-by | cut -f 2 -d ':' | sed 's/ *//'`

if echo $resultext | grep -i -e 'railcom' -e 'crtc' -e 'railway'

then echo $ip/$mask';' >> crc

elif echo $resultext | grep -i -e 'cncgroup' -e 'netcom'

then echo $ip/$mask';' >> cnc

elif echo $resultext | grep -i -e 'chinanet' -e 'chinatel'

then echo $ip/$mask';' >> telcom_acl

elif echo $resultext | grep -i -e 'unicom'

then echo $ip/$mask';' >> unicom

elif echo $resultext | grep -i -e 'cmnet'

then echo $ip/$mask';' >> cmnet

else

echo $ip/$mask';' >> other_acl

fi

done

【Shell脚本获取国内各大运营商网段脚本分享】相关文章:

shell获取命令行参数示例分享

shell监控linux系统进程创建脚本分享

Shell脚本判断Linux系统是32位还是64位的几种方法分享

Shell脚本模拟多线程功能分享

Shell脚本批量修改文件后缀名代码分享

shell脚本实现拷贝大文件显示百分比的代码分享

shell中的数组操作小结和冒泡排序实现脚本分享

25个好用的Shell脚本常用命令分享

Shell脚本制作的终端会话回放功能脚本分享

Shell实现多级菜单系统安装维护脚本实例分享

精品推荐
分类导航