Created
July 11, 2017 07:29
-
-
Save jackyshan/521e4aa0cd66a331c5364fb2c47dbe17 to your computer and use it in GitHub Desktop.
检查ss客户端地址在哪个城市
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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