2009年7月18日星期六

SHOW ME THE IP

从内网获得路由器的广域网IP地址的Python脚本(仅限特定硬件和特定固化软件):
#! /usr/bin/env python
"""
Get my IP address from my TP-Link TL-R402 router.
Pan Yongzhi@ Jul 18, 2009
"""
import urllib2
x = urllib2.HTTPPasswordMgrWithDefaultRealm()
x.add_password(None, 'http://192.168.1.1', 'user', 'pass')
auth = urllib2.HTTPBasicAuthHandler(x)
opener = urllib2.build_opener(auth)
urllib2.install_opener(opener)
flob = urllib2.urlopen('http://192.168.1.1/userRpm/StatusRpm.htm')
"""IP address contained in line 75 of the web page, looks like this:
0, "00-21-27-3C-01-A5", "221.217.204.232", 3, "255.255.255.255", 0, 0, "221.217.204.232", 0, 1, 0, "202.106.46.151, 202.106.195.68", "0 day 00:19:31", "up",
"""
print flob.readlines()[74].split(',')[2].strip().strip('"')

2009年7月15日星期三

还是进程交织快

第一种方法,打包和加密分别进行,共用时46分钟:
$ time tar cf tux.tar tux/

real 23m45.672s
user 0m4.290s
sys 0m52.546s
$ time openssl enc -e -des3 -salt -in tux.tar -out tux.090713.enc
enter des-ede3-cbc encryption password:
Verifying - enter des-ede3-cbc encryption password:

real 22m13.738s
user 8m20.402s
sys 0m55.287s

第二种方法,把打包和加密进程交织进行,共用时25分钟:

$ time tar cf - tux/ | openssl enc -e -des3 -salt -out tux.090713.enc-again
enter des-ede3-cbc encryption password:
Verifying - enter des-ede3-cbc encryption password:

real 24m56.357s
user 8m26.497s
sys 1m12.961s

文件加密解密脚本

2006年在网上找到的,需要OpenSSL,方便好用:

#! /bin/bash
#
usage()
{
echo "Usage: encrypt foo .. encrypts foo, stores in foo.enc"
echo " encrypt -d foo.enc .. decrypts foo.enc, stores in foo"
echo " encrypt -c foo.enc .. decrypts foo.enc, writes to stdout"
}

if [ $# -eq 1 -a "$1" = "-h" ]
then
usage
elif
[ $# -eq 2 -a "$1" = "-c" ]
then
openssl enc -d -des3 -in $2
elif
[ $# -eq 2 -a "$1" = "-d" ]
then
openssl enc -d -des3 -in $2 -out ${2%.enc}
elif
[ $# -eq 1 -a -f "$1" ]
then
openssl enc -e -des3 -salt -in $1 -out $1.enc
else
usage
fi

2009年7月9日星期四

磁盘错误

某天用着用着突然音乐声音开始一卡一卡,电脑很慢,dmesg发现硬盘错误。重启
后也是磁盘错误进不去,用Ubuntu的Live CD也无效。于是从FreeBSD启动进去试图
磁盘检错,没找到怎么检查。重启后Ubuntu又能进去了。莫非是FreeBSD在启动中
已经把硬盘都查错了?