def ipbydate(request, ip, date): adb = AggDB() adb.lookup_tz = requested_tz(request) adb.connect(settings.APIV1_AGGDB_HOST, settings.APIV1_AGGDB_USER, settings.APIV1_AGGDB_PASS, settings.APIV1_AGGDB_DB) body = [] dt = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S") for item in adb.lookup_by_ip(ip, dt): body.append(item) adb.close() return HttpResponse(json.dumps(body, encoding="latin_1"), mimetype="application/json")
def ip(request, ip): adb = AggDB() adb.lookup_tz = requested_tz(request) adb.connect(settings.APIV1_AGGDB_HOST, settings.APIV1_AGGDB_USER, settings.APIV1_AGGDB_PASS, settings.APIV1_AGGDB_DB) body = [] for item in adb.lookup_by_ip(ip): body.append(item) adb.close() return HttpResponse(json.dumps(body, encoding="latin_1"), mimetype="application/json")
def main(argv): db = AggDB() cfg = ConfigParser() cfg.read(config_filename) db.connect(cfg.get("MySQL", "host"), cfg.get("MySQL", "user"), cfg.get("MySQL", "pass"), cfg.get("MySQL", "db")) target_date = datetime.strptime(argv[1], "%Y-%m-%d %H:%M:%S") print fmt.format("IP", "MAC", "Start", "End", "Circuit-ID", "Remote-ID", "giaddr") for item in db.lookup_by_ip(argv[0], target_date): print fmt.format(item["ip"], item["mac"], item["start"], item["end"], item["circuit_id"], item["remote_id"], item["giaddr"])