ipinfo.py 857 B

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