#!/usr/bin/python

import sys
import json

data = json.loads(open('/usr/local/Reductor/cache/https_resolv.json').read())

if len(sys.argv) == 3 and sys.argv[1] == '--ip':
	domains = [d for d, v in data.items() if v.get('ip').get(sys.argv[2])]
	print json.dumps(domains, indent=4, ensure_ascii=False)
	sys.exit(0)

if len(sys.argv) == 2 and sys.argv[1] != '--help':
	print json.dumps(data.get(sys.argv[1]), indent=4)
	sys.exit(0)

print "Usage:"
print "./cache_ctl --ip 1.2.3.4"
print "./cache_ctl example.com"
