这两天学着自已制作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
|
然后用
处理一下格式,后面就转到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分别是电信联通和除他们之外的地址表。
阅读(6539) | 评论(2) | 转发(0) |