Created
May 14, 2021 11:39
-
-
Save myl7/09546ebf2f618a7689c1ce7f579316f8 to your computer and use it in GitHub Desktop.
Filter goaccess json with IP ranges
This file contains hidden or 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
import json | |
from netaddr import IPSet, IPAddress | |
with open('ipset.txt') as f: | |
ipset = IPSet(list(f)) | |
with open('visitors.json') as f: | |
addrs = json.load(f) | |
res = [addr for addr in addrs if IPAddress(addr['data']) in ipset] | |
with open('res.json', 'w') as f: | |
json.dump(res, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment