因为有需要做Android相关的开发工作,很多时候要穿越之后才能做事情;
如Android文件加密预研、Android NDK/SDK的下载,都需要使用得到Google;
但是穿越之后,访问国内网站就不是那么方便了,所以,写一脚本,在需要的时候直接调用下就可以直达国内网站了;
1 #!/bin/bash - 2 #=============================================================================== 3 # 4 # FILE: direct_conn.sh 5 # 6 # USAGE: ./direct_conn.sh 7 # 8 # DESCRIPTION: 9 # 10 # OPTIONS: --- 11 # REQUIREMENTS: --- 12 # BUGS: --- 13 # NOTES: --- 14 # AUTHOR: linkscue (scue), linkscue@gmail.com 15 # ORGANIZATION: 16 # CREATED: 2014年09月07日 17时11分00秒 CST 17 # REVISION: --- 18 #=============================================================================== 19 20 test -n $1 || exit # get param 21 sudo echo -n # get route 22 23 act=add # 默认是添加邮件操作 24 gw=192.168.1.1 # 默认网关,未穿越城墙之前 25 26 # function 27 get_addr(){ 28 curl -sL http://www.ip138.com/ips1388.asp\?ip\=$1\&action\=1 |\ 29 grep -i $1 |grep -o '[0-9.]\+<'|awk -F'<' '{print $1}' 30 } 31 32 case $1 in 33 d|del|delete) 34 act=del 35 shift 36 ;; 37 a|add) 38 act=add 39 shift 40 ;; 41 esac 42 43 # do 44 for i in $@; do 45 ip=$i 46 echo $i | grep -q '[a-zA-Z]\+' &&\ 47 ip=$(get_addr $(echo ${i##http://}|grep -o '[a-zA-Z0-9.-]\+')) 48 echo "route: $act $ip" 49 case $act in 50 add ) 51 route -n|grep -q $ip ||\ 52 sudo route $act -net $ip netmask 255.255.255.255 gw $gw metric 0 53 ;; 54 del ) 55 route -n|grep -q $i &&\ 56 sudo route $act -net $ip netmask 255.255.255.255 gw $gw metric 0 57 ;; 58 esac 59 done
使用方法:
可批量操作
1) 添加路由: ./direct_conn.sh add 203.130.61.21 pan.baidu.com http://www.baidu.com/ ..
2) 删除路由: ./direct_conn.sh del 203.130.61.21 pan.baidu.com http://www.baidu.com/ ..