Skip to content

Instantly share code, notes, and snippets.

@Expost
Last active May 11, 2019 05:32
Show Gist options
  • Save Expost/478af60a29a13c02bea4e0fc841d4330 to your computer and use it in GitHub Desktop.
Save Expost/478af60a29a13c02bea4e0fc841d4330 to your computer and use it in GitHub Desktop.
从v2ray的access log中获取访问ip的地址信息,这需要ipdb库以及ipdb离线库。
import re
import ipdb
f = open("access.log")
d = dict()
r_ip = re.compile("(\d+\.\d+\.\d+\.\d+):\d+ accept")
r_time = re.compile("\d+/\d+/\d+")
for line in f:
try:
ip = r_ip.findall(line)[0]
ttime = r_time.findall(line)[0]
if d.get(ttime):
if ip not in d.get(ttime):
d[ttime].append(ip)
else:
d[ttime] = []
d[ttime].append(ip)
except Exception as e:
#print("error line is ", line)
pass
db = ipdb.City("ip.ipdb")
for key in d:
print("=============%s=============" %key)
for ip in d[key]:
print("ip:%s -> %s" %(ip, ".".join(db.find(ip, "CN"))))
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment