-
Notifications
You must be signed in to change notification settings - Fork 26
/
ipinfo.py
26 lines (22 loc) · 857 Bytes
/
ipinfo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import re, ipdb, ipaddress
db = ipdb.BaseStation("/app/qqwry.ipdb")
with open("/app/iplist.txt", "r") as f:
data = f.read()
iplist = re.findall(r"\b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b", data)
for ip in iplist:
try:
ipaddress.ip_address(ip).is_global
city = db.find(ip, "CN")
print(ip + " @" + city[0] + city[1] + city[2] + city[3])
except:
pass
# 统计日志中IP排名写到iplist.txt,批量查IP地址信息,最新日志100条
"""
docker logs nginx-php 2>/dev/null \
| grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' \
| sort | uniq -c| sort -nrk 1 | head -n 100 | tee iplist.txt
docker exec -it python3 python3 ipinfo.py
docker logs nginx-php 2>/dev/null | tail -100 \
| grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' \
| sort | uniq -c| sort -nrk 1 | head -n 100 | tee iplist.txt
"""