Skip to content

Instantly share code, notes, and snippets.

@jackyshan
Created July 11, 2017 07:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackyshan/521e4aa0cd66a331c5364fb2c47dbe17 to your computer and use it in GitHub Desktop.
Save jackyshan/521e4aa0cd66a331c5364fb2c47dbe17 to your computer and use it in GitHub Desktop.
检查ss客户端地址在哪个城市
# -*- coding: utf-8 -*-
import re, urllib2, json, time
import sys
reload(sys)
sys.setdefaultencoding('utf8')
file = open('server.log')
list = file.readlines()
file.close()
pattern = re.compile(r'(\d+\.){3}\d+')
clists = []
warninglist = []
for index in range(0, len(list)):
info = list[index]
m = pattern.search(info)
if m:
m = m.group()
try:
clists.index(m)
except:
print info
clists.append(m)
resp = urllib2.urlopen('http://ip.taobao.com/service/getIpInfo.php?ip='+m)
resp = resp.read()
respjson = json.loads(resp)
city = respjson['data']['city']
if '广州' not in city:
try:
warninglist.index(city)
except:
warninglist.append(city)
time.sleep(1)
#print clists
#打印异常
if len(warninglist) > 0:
print '异常地址'
print warninglist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment