Skip to content

Instantly share code, notes, and snippets.

View upbit's full-sized avatar

Zhou Hao upbit

  • China
View GitHub Profile
# -*- coding: utf-8 -*-
##
## dump object to string
##
# XXX - ''.join([(len(`chr(x)`)==3) and chr(x) or '.' for x in range(256)])
__vis_filter = """................................ !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[.]^_`abcdefghijklmnopqrstuvwxyz{|}~................................................................................................................................."""
def hexdump(buf, length=16):
"""form dpkt: Return a hexdump output string of the given buffer."""
@upbit
upbit / update_imouto.host.sh
Last active August 29, 2015 14:05
MacOS用的imouto.host自动更新脚本
#!/bin/bash
IMOUTO_HOST="https://www.dropbox.com/sh/lw0ljk3sllmimpz/AAC-n6LmtWbdlKQRbdEa0QUoa/imouto.host.7z?dl=1"
# download hosts file
curl -L -o imouto.host.7z ${IMOUTO_HOST}
# unzip
./7za x imouto.host.7z imouto.host.txt
awk '{ if (NR==1) sub(/^\xef\xbb\xbf/,""); print }' imouto.host.txt > imouto.host.txt
@upbit
upbit / hosts_to_dnsmasq.py
Created August 28, 2014 13:16
将hosts中的网站,转为dnsmasq的conf规则
# -*- coding: utf-8 -*-
HOSTS = """
# 将gfw hosts内容粘贴到这里
"""
BLACK_LIST = """com.co.jp
akamaihd.net
angrybirds.com
@upbit
upbit / pexpect_ssh.py
Last active August 29, 2015 13:57
python-pexpect demo
import pexpect # download from https://github.com/pexpect/pexpect
def remote_ssh_cmd(ip, cmd, user="root", passwd=""):
ssh = pexpect.spawn('ssh %s@%s "%s"' % (user, ip, cmd))
r = ''
try:
i = ssh.expect(['password: ', 'continue connecting (yes/no)?'])
if i == 0 :
ssh.sendline(passwd)
elif i == 1: