Skip to content

Instantly share code, notes, and snippets.

@xixitalk
xixitalk / updateDDNS.sh
Created May 29, 2013 11:34
update 3322.org DDNS with API
#!/bin/sh
if [ ! -e /tmp/dnsip.txt ] ; then
ping mydomain.f3322.org -c1 | grep PING | awk '{ print $3 }' | sed 's/[()]//g' > /tmp/dnsip.txt
fi
mydnsip=$(head -1 /tmp/dnsip.txt)
curl -s http://icanhazip.com > /tmp/ip.txt
myip=$(head -1 /tmp/ip.txt)
@xixitalk
xixitalk / isChinaIP.py
Created March 12, 2013 11:39
算法:判断是否是中国IP
#/usr/bin/python
#coding: utf-8
global_ip_dict = [[[] for col in range(256)] for row in range(256)]
#input:apnic|CN|ipv4|112.0.0.0|4194304|20081215|allocated
#output:addr1,addr2,addr3,addr4,ip_num
def analyseLine(ip_line):
ip_str_list = ip_line.split('|')
if len(ip_str_list) < 7:
@xixitalk
xixitalk / gist:4969986
Last active December 13, 2015 20:28
为flask_twip添加图片代理
def getimg(self):
imgurl = request.args.get('imgurl','')
if len(imgurl) == 0:
return '<form action="/twip/getimg" method="get"><input type="text" size="50" name="imgurl" /> <input type="submit" value="submit" />'
urlobj = urllib2.urlopen(imgurl)
header = urlobj.info()
headers = {}
headers['Content-Type'] = header.get('Content-Type','image/png')
content = urlobj.read()
status = urlobj.getcode()