Skip to content

Instantly share code, notes, and snippets.

@myl7
Created May 14, 2021 11:39
Show Gist options
  • Save myl7/09546ebf2f618a7689c1ce7f579316f8 to your computer and use it in GitHub Desktop.
Save myl7/09546ebf2f618a7689c1ce7f579316f8 to your computer and use it in GitHub Desktop.
Filter goaccess json with IP ranges
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