需要产生0到FF的目录
#!/bin/bash for (( a=0 ; a<256 ; a++ )); do b=`echo ""$a" 16 o p" | dc`;echo $b; mkdir $b done
需要产生0到FF的目录
#!/bin/bash for (( a=0 ; a<256 ; a++ )); do b=`echo ""$a" 16 o p" | dc`;echo $b; mkdir $b done
使用tcpdump在服务器上抓包。
/usr/sbin/tcpdump -i eth0 -G 3600 -s 0 -w /test.cap
-i 网卡信息
-G 抓N秒后停止
-s 抓取完整的包,0为抓全部包,不然包会不完整
-w 文件位置
需求是是要将密码存在数据库里,所以要加密解密是可逆的,在数据库里不要有特殊字符,防止数据库备份和恢复中出错。
安装PyCrypto,可以用AES和DES。我使用DES加解密。加密后将密文转为16进制,在入库。测试代码如下。
#!/bin/python #-*- coding:utf-8 -*- # Filename: # Revision: # Date: 2013-06-07 # Author: simonzhang # web: www.simonzhang.net # Email: simon-zzm@163.com ### END INIT INFO # easy_install PyCrypto from binascii import b2a_hex, a2b_hex from Crypto.Cipher import DES key = '12345678' #长度必须是8位的 text = 'simonzhang.net ' #长度必须是8的倍数,我用空格补的 # 实例化 obj = DES.new(key) # 加密 cryp = obj.encrypt(text) pass_hex = b2a_hex(cryp) print pass_hex print '=' * 20 # 解密 get_cryp = a2b_hex(pass_hex) after_text = obj.decrypt(get_cryp) print after_text
最初只是简单抓取没有问题,现在要在线上做抓取时发现很多问题。比如:长时间使用报500错误,需要cookie,有的网站有gzip压缩。本段代码已经解决以上问题,但是字符集问题没有处理,因为我要抓的页面没字符问题。我将代码放在tornado上跑,分析的服务器请求后直接抓取返回信息给分析的服务器。
import urllib2 import cookielib def get_url_context(_url): # cookie cj = cookielib.CookieJar() _myopener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) _req = urllib2.Request("http://%s" % _url) # add head _req.add_header("Accept-Language", "zh-cn") _req.add_header("Content-Type", "text/html; charset=utf-8") _req.add_header("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)") # open _get_page_data = _myopener.open(_req) _get_headers = _get_page_data.info() _get_rawdata = _get_page_data.read() _get_page_data.close() # check gzip if ('Content-Encoding' in _get_headers and _get_headers['Content-Encoding']) or \ ('content-encoding' in _get_headers and _get_headers['content-encoding']): import gzip import StringIO data = StringIO.StringIO(_get_rawdata) gz = gzip.GzipFile(fileobj=data) _get_rawdata = gz.read() gz.close() return _get_rawdata