工作,学习,生活,这里将会有一些记录. 备用域名:http://meisw.wdlinux.cn 注册 | 登陆
浏览模式: 标准 | 列表2010年12月的文章

Dns信息收集工具集合

dnswalk, dnstracer,dnsenum
DNSwalk是DNS debugger. 用于域的转换和查询数据库
命令行中的域名必须以.结尾,你可有使用普通域名例如:dnswalk example.com. 或者反域名例如: dnswalk 3.2.1.in-addr.arpa

命令举例:
#./dnswalk www.g.cn.

下载地址:http://sourceforge.net/projects/dnswalk/
-------------------
dnstracer,向指定域名服务器发送非递归域名请求。
非递归请求的意思是,如果域名服务器知道,那么它会返回请求数据。
如果域名服务器不知道,它会返回授权域的域名服务器或返回根域名服务器的地址。
命令举例:
dnstracer www.mavetju.org

下载地址:http://www.mavetju.org/download/dnstracer-1.9.tar.gz
-------------
dnsenum的目的是尽可能收集一个域的信息。1) 主机地址信息,(A record).
2) 域名服务器 (threaded).
3) MX record (threaded).
4) 在域名服务器上执行axfr请求.
5)通过google脚本得到扩展域名或子域名信息(google query = “allinurl: -www site:domain”).
6) 提取子域名并查询.
7) 计算C类地址,并执行whois查询.
8) 执行反向查询.
9) 把地址段写入文件domain_ips.txt.

命令举例:
./dnsenum.pl cnn.com

常用参数命令举例:
./dnsenum.pl --enum -f dns.txt --update a -r remote
下载地址:http://code.google.com/p/dnsenum/

 

mod_pagespeed Too many links

Wed Nov 24 01:01:33 2010] [error] [mod_pagespeed 0.9.8.1-215] /var/mod_pagespeed/files/30a3a4392832681d4fa3f0b9d1346aca.lock:0: removing dir (code=2 No such file or directory)[Wed Nov 24 01:01:33 2010] [error] [mod_pagespeed 0.9.8.1-215] /var/mod_pagespeed/files/566c482f383311076f14791b78aad40b.lock:0: creating dir (code=31 Too many links)

http://code.google.com/p/modpagespeed/issues/detail?id=111

 

深入理解Python yield

Python模块学习 ---- StringIO, cStringIO 内存文件(转)

StringIO的行为与file对象非常像,但它不是磁盘上文件,而是一个内存里的“文件”,我们可以将操作磁盘文件那样来操作StringIO。一个简单的例子,让你对StringIO有一个感性的认识:

1   #coding=gbk
2    
3   import StringIO, cStringIO, sys
4    
5   s = StringIO.StringIO("JGood is a handsome boy")
6   s.write("JGood is a handsome boy \r\n")
7   s.write('okkkk中国')
8   s.seek(0)
9   print s.read()
10    
11   #最后4个字节
12   s.seek(-4, 2)
13   print s.read()
14    
15   #---- 结果 ----
16   #JGood is a handsome boy 
17   #okkkk中国
18   #中国

通过例子,我们看到了StringIO的行为,基本与file一致。StringIO提供了一个方法,可以方便的获取其中的数据:StringIO.getvalue()。如果使用read方法获取其中的数据,必须通过seek先设置"文件指针"的位置。

  Python标准模块中还提供了一个cStringIO模块,它的行为与StringIO基本一致,但运行效率方面比StringIO更好。但使用cStringIO模块时,有几个注意点: 1. cStringIO.StringIO不能作为基类被继承;2. 创建cStringIO.StringIO对象时,如果初始化函数提供了初始化数据,新生成的对象是只读的。所以下面的代码是错误的:s = cStringIO.StringIO("JGood\n"); s.write("OOOKKK");

UPX使用手册,简介(转)

UPX 是一款先进的可执行程序文件压缩器
压缩过的可执行文件体积缩小50%-70%
这样减少了磁盘占用空间、网络上传下载的时间和其它分布以及存储费用。

通过 UPX 压缩过的程序和程序库完全没有功能损失
和压缩之前一样可正常地运行
对于支持的大多数格式没有运行时间或内存的不利后果。

UPX 支持许多不同的可执行文件格式
包含 Windows 95/98/ME/NT/2000/XP/CE 程序和动态链接库、DOS 程序、Linux 可执行文件和核心。

参数说明:
Usage: upx [-123456789dlthVL] [-qvfk] [-o file] file..

Commands:
   -1      compress faster                    -9     compress better
   -d      decompress                         -l     list compressed file
   -t      test compressed file               -V     display version number
   -h      give more help                     -L     display software license
Options:
   -q      be quiet                           -v     be verbose
   -oFILE write output to 'FILE'
   -f      force compression of suspicious files
   -k      keep backup files
file..    executables to (de)compress

Type 'upx --help' for more detailed help.

UPX comes with ABSOLUTELY NO WARRANTY; for details visit http://upx.sf.net

python

source = ['/home/swaroop/byte', '/home/swaroop/bin']
# If you are using Windows, use source = [r'C:\Documents',r'D:\Work'] or somethi
ng like that
# 2. The backup must be stored in a main backup directory
target_dir = '/mnt/e/backup/' # Remember to change this to what you will be usin
g
# 3. The files are backed up into a zip file.
# 4. The name of the zip archive is the current date and time
target   =   target_dir   +  time.strftime('%Y%m%d%H%M%S') + '.zip'


if not os.path.exists(today): 
   os.mkdir(today) # make directory 
   print 'Successfully created directory', today


comment = raw_input('Enter a comment --> ')
if len(comment) == 0: # check if a comment was entered
   target = today + os.sep + now + '.zip'
else:
   target = today + os.sep + now + '_' + \
      comment.replace(' ', '_') + '.zip'

 

zip_command = "zip -qr '%s' %s" % (target, ' '.join(source))
# Run the backup
if os.system(zip_command) == 0:
  print 'Successful backup to', target
else:
  print 'Backup FAILED'

 

 

subprocess再解析

之前已经写过一篇关于Python subprocess的帖子了,subprocess是Python下标准的用于进程创建、通讯的模块,这里再补充一些,注意:我还一直坚守Python2.x,所以不一定适合Python 3。

subprocess简单用法

这是最简单的用法:

p=subprocess.Popen("dir", shell=True)
p.wait()

shell参数根据你要执行的命令的情况来决定,上面是dir命令,就一定要shell=True了,p.wait()可以得到命令的返回值,没有问题。

进程通讯

如果想得到进程的输出,管道是个很方便的方法,这样:

p=subprocess.Popen("dir", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stdoutput,erroutput) = p.communicate()

p.communicate会一直等到进程退出,并将标准输出和标准错误输出返回,这样就可以得到子进程的输出了,上面,标准输出和标准错误输出是分开的,也可以合并起来,只需要将stderr参数设置为subprocess.STDOUT就可以了,这样子:

p=subprocess.Popen("dir", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
(stdoutput,erroutput) = p.communicate()

如果你想一行行处理子进程的输出,也没有问题:

p=subprocess.Popen("dir", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
    buff = p.stdout.readline()
    if buff == '' and p.poll() != None:
        break

死锁

但是如果你使用了管道,而又不去处理管道的输出,那么小心点,如果子进程输出数据过多,死锁就会发生了,比如下面的用法:

p=subprocess.Popen("longprint", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p.wait()

longprint是一个假想的有大量输出的进程,那么在我的xp, Python2.5的环境下,当输出达到4096时,死锁就发生了。当然,如果我们用p.stdout.readline或者p.communicate去清理输出,那么无论输出多少,死锁都是不会发生的。或者我们不使用管道,比如不做重定向,或者重定向到文件,也都是可以避免死锁的。

异步subprocess

无论是使用readline还是communicate,这里有个问题是:他们都是同步的,你没有办法在等待子进程输出的同时做点别的什么事情,标准的subprocess是不支持异步和子进程交互的,幸好,幸好,有人提供了Python 3下的异步方法,我移植到Python2.5下面,可以这样用了:

p=subprocess.Popen("dir", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
while True:
    buff = p.asyncread(timeout=0.5)
    if buff == '' and p.poll() != None:
        break

这里带一个超时去读取子进程的输出,如果超时还没有输出,没关系,父进程可以干点别的什么事情,看起来很棒,subprocess的改动部分代码比较长,不在这里贴了。

关闭
在Python 2.6的subprocess模块中,新增加了一个小的接口就是Terminate,用于进程的终结,可惜可惜,十分遗憾,Windows下,这个Terminate只能杀死subprocess创建的进程,而不能杀死其子进程,如果我们明确知道创建的进程没有子进程,当然可以用这个接口,如果不肯定,则这个接口就没什么用了。

举个简单的例子,如果用shell=True的参数让subprocess创建进程,那么就会多出一个额外的cmd进程,这时用Terminate终结的就是这个cmd进程,而真正那个我们创建的进程则不会被终结。

有很多方法可以对付这个问题,但有一个简单的方法是使用Windows自己提供的taskkill命令,它有一个/T参数,可以杀死一个进程树,正是我们所需要的。subprocess创建的进程有一个pid属性,把pid传给taskkill就ok了。

http://www.liuzhongshu.com/code/subprocess-detail.html

Pyinstaller建立linux下Python的独立可执行文件

以下内容假定已安装好Python 2.4/2.5
一、下载并编译pyinstaller(只需做一次,以后可直接做第二步)
1.下载pyinstaller,现在的版本是1.3
(1)wget http://pyinstaller.hpcf.upr.edu/source/1.3/pyinstaller_1.3.tar.gz

2.解包进入源码目录
(1)tar zxv pyinstaller_1.3.tar.gz
(2)cd pyinstaller-1.3/source/linux

3.编译源代码
(1)python Make.py 生成python的 .pyc文件

如无错误,则出现如下提示(只有一行):
Now run "make" to build the targets: ../../support/loader/run ../../support/loader/run_d

(2)make 连接生成linux的 .o 文件

4.生成编译配置文件
(1)python Configure.py 生成config.dat配置文件

二、编译独立运行的python可执行文件

1.生成spec文件
python pyinstaller-1.3/Makespec.py --onefile --upx linuxlaptop.py

参数说明:
--onefile 生成单文件
--upx 生成压缩的文件(可减小执行文件体积,需先安装upx软件包)


2.生成最终的可执行文件
python pyinstaller-1.3/Build.py linuxlaptop.spec

执行完成后将在当前目录生成可执行的linuxlaptop文件,如有问题欢迎与我交流:linuxlaptop.cn。
原文:http://bbs.chinaunix.net/thread-1328460-1-1.html

============================个人实践=============================
系统:Ubuntu 8.0.4
安装相关包:apt-get install libc6-dev python-dev zlib1g-dev
cd source/linux
python ./Make.py
make


cd ../../
python Configure.py
/pyinstaller-1.3/Makespec.py --onedir --icon=img/imac.ico my.py
python /pyinstaller-1.3/Build.py my.spec


这时会提示pyinstaller-1.3中的几个包语法错误,估计源码包是在window下调试产生unix不识别的字符,典型的是换行符。
安装dos2unix:sudo apt-get install tofrodos
dos2unix /pyinstaller-1.3/pyinstaller-1.3/optparse.py......(6个文件左右)

再运行:python /pyinstaller-1.3/Build.py my.spec
搞定,生成了distmy目录,里头有好多.o文件,类似于win下的dll:)

Records:65123456789