def test_metadata(self): net = ParseNetxml(get_asset_dic() + "/network.netxml") meta = net.get_metadata() self.assertDictEqual(meta, { "kismet_version": "2013.03.R0", "start_time": "2014-11-15 13:00:00" })
def get_network(self): netxml = ParseNetxml(self._file, "%Y-%m-%dT%H:%M:%S.0") for net in netxml.get_networks(): bssid = net["bssid"] self._fix_network(net, bssid) self._fix_clients(net, bssid) yield net
def test_get_networks(self): self.maxDiff = None net = ParseNetxml(get_asset_dic() + "/network.netxml") data = [] for i in net.get_networks(): data.append(i) expected = "" with open(get_asset_dic() + "/network.netxml.json") as f: expected = json.loads(f.read()) self.assertListEqual(expected, data)
def insert(self): print(json.dumps(self._files, indent=4)) for file in self._files: gpsxml = file + ".gpsxml" netxml = file + ".netxml" meta = {} gps = ParseGpsxml(file=gpsxml, date_format="%Y-%m-%dT%H:%M:%S.0") meta.update(gps.get_metadata()) elk_meta = self._elk.search(doc_type="files", size=1, q="file:\"%s\"" % (meta["file"],)) if elk_meta["hits"]["total"] > 0: print("File %s exists in elasticsearch!" % (netxml,)) continue try: net = ParseNetxml(file=netxml, date_format="%Y-%m-%dT%H:%M:%S.0") meta.update(net.get_metadata()) meta["time"] = meta["start_time"] del meta["start_time"] file_id = self._elk.insert("files", meta)["_id"] print("Inserting networks to database from " + netxml) net = InsertNetxmlElk(self._elk, netxml, file_id) net.insert() print("Inserting gpspoints to database from " + gpsxml) gps = InsertGpsxmlElk(self._elk, gpsxml, file_id) gps.insert() except Exception as e: print("Error :( " + str(e))
def test_ret_val(self): net = ParseNetxml(get_asset_dic() + "/network.netxml") self.assertEqual(0, net._ret_val(0, "")) self.assertEqual(5, net._ret_val(0, "5")) self.assertEqual(10, net._ret_val(0, 10)) self.assertEqual(.0, net._ret_val(.0, "")) self.assertEqual(.2, net._ret_val(.0, "0.2")) self.assertEqual(.5, net._ret_val(.0, .5)) self.assertEqual(True, net._ret_val(True, "")) self.assertEqual(True, net._ret_val(True, True)) self.assertEqual(True, net._ret_val(True, "true")) self.assertEqual(True, net._ret_val(True, False)) self.assertEqual(False, net._ret_val(True, "false")) self.assertEqual(False, net._ret_val(False, "")) self.assertEqual(True, net._ret_val(False, True)) self.assertEqual(True, net._ret_val(False, "true")) self.assertEqual(False, net._ret_val(False, False)) self.assertEqual(False, net._ret_val(False, "false")) self.assertEqual("", net._ret_val("", None)) self.assertEqual("", net._ret_val("", "")) self.assertEqual("0", net._ret_val("", "0")) self.assertEqual("def", net._ret_val("def", None)) self.assertEqual("def", net._ret_val("def", "")) self.assertEqual("TeST", net._ret_val("", "TeST"))