Chinaunix首页 | 论坛 | 博客
  • 博客访问: 149212
  • 博文数量: 13
  • 博客积分: 2000
  • 博客等级: 大尉
  • 技术积分: 390
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-09 09:55
文章分类

全部博文(13)

文章存档

2010年(4)

2009年(5)

2008年(4)

我的朋友

分类: LINUX

2010-03-15 11:49:15

  这两天学着自已制作ROS用的网通电信路由表,记下过程,因为不熟悉LINUX,颇为曲折
1、用网上的这段SHELL生成

#!/bin/sh
FILE=/home/xxx/apnic.txt

wget -O $FILE
grep 'apnic|CN|ipv4|' $FILE | cut -f 4,5 -d'|'|sed -e 's/|/ /g' | while read ip cnt
do
echo $ip:$cnt
         mask=$(cat << EOF | bc | tail -1
pow=32;
define log2(x) {
if (x<=1) return (pow);
pow--;
return(log2(x/2));
}
log2($cnt)
EOF)

NETNAME=`whois $ip | sed -e '/./{H;$!d;}' -e 'x;/netnum/!d' |grep ^netname | sed -e 's/.*: \(.*\)/\1/g' | sed -e 's/-.*//g'`
DESCR=`whois $ip | sed -e '/./{H;$!d;}' -e 'x;/netnum/!d' |grep ^descr | sed -e 's/.*: \(.*\)/\1/g' | sed -e 's/-.*//g'`
echo $ip/$mask/$NETNAME/$DESCR>> cn.net
done


生成的cn.net如下格式

27.8.0.0/13/ UNICOM/ China Unicom Chongqing Province Network China Unicom
58.14.0.0/15/netname: JNGDNET/ Jinan Radio &TV Wellunited Digital Cable TV Co., Ltd 3F Sanjianyinyuan Building,No.22 minsheng Road, Jinan, Shandong, P.R.China


然后用

unix2dos cn.net

处理一下格式,后面就转到WIN了,自己对LINUX脚本不熟,不然整个过程都可以在LINUX下完成的……


2、用这个批处理

find "CHINANET" %1>>telecom.txt
find "CHINANET" %1 /v >>temp.txt
find "Telecom" temp.txt >>telecom.txt
find "Telecom" temp.txt /v >>notelecom.txt
del temp.txt
find "UNICOM" notelecom.txt >>unicom.txt
find "UNICOM" notelecom.txt /v >>temp.txt
find "CNC" temp.txt >>unicom.txt
find "CNC" temp.txt /v >>other.txt
del temp.txt
del notelecom.txt
@echo / ip route rule >>routecnc.rsc
@echo / ip route rule >>route_tc.rsc
@echo / ip firewall address-list >>list_cnc.rsc
@echo / ip firewall address-list >>list_tc.rsc
for /f "eol=- tokens=1,2 delims=/" %%i in (telecom.txt) do @echo add dst-address=%%i/%%j action=lookup table=cnc comment="" disabled=no >>route_tc.rsc
for /f "eol=- tokens=1,2 delims=/" %%i in (telecom.txt) do @echo add list=CNC address=%%i/%%j comment="" disabled=no >>list_tc.rsc
for /f "eol=- tokens=1,2 delims=/" %%i in (unicom.txt) do @echo add dst-address=%%i/%%j action=lookup table=cnc comment="" disabled=no >>routecnc.rsc
for /f "eol=- tokens=1,2 delims=/" %%i in (unicom.txt) do @echo add list=CNC address=%%i/%%j comment="" disabled=no >>list_cnc.rsc

会生成七个文件:list_cnc.rsc和list_tc.rsc是地址导入脚本,route_tc.rsc和routecnc.rsc是路由导入脚本,telecom.txt、unicom.txt和other.txt分别是电信联通和除他们之外的地址表。
阅读(6518) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-03-15 17:08:49

这里也分发用于路由表,准不准确就自己评估啦。 htp://www.tcp5.com/routingtable/

chinaunix网友2010-10-25 17:55:12

可以去这里看看, http://policy-routing.wangfei.me/ 通过全球路由表信息,程序会每两个小时自动分析一份实时的中国地区ISP策略路由表。使用相同到方法,可以分析任何国家的精确路由表。