ich bräuchte mal so einen kleinen Anschubser beim Auslesen von JSON-Format. Mit dem großartigen Tutorial von TI-994A im englischsprachigen Tutorial bin ich auch bereits weit gekommen, hänge jetzt aber beim Auslesen von „Unterobjekten“.
Das JSON-Format beziehe ich aus einer sqlite-DB vom WLAN-Monitor „KISMET“.
Anbei ein gekürzter Auszug:
Code: Alles auswählen
{
"kismet.device.base.phyname" : "IEEE802.11",
"kismet.device.base.crypt" : "WPA2-PSK",
"kismet.device.base.mod_time" : 1580395087,
"kismet.device.base.name" : "Mein-WLAN",
"kismet.device.base.type" : "Wi-Fi AP",
"kismet.device.base.last_time" : 1580395086,
"kismet.device.base.channel" : "9",
"kismet.device.base.packets.error" : 0,
"kismet.device.base.basic_type_set" : 1,
"dot11.device" : {
"dot11.device.probe_fingerprint" : 0,
"dot11.device.num_advertised_ssids" : 1,
"dot11.device.bss_timestamp" : 27310967158008,
"dot11.device.wps_m3_count" : 0,
"dot11.device.associated_client_map" : {},
"dot11.device.last_beaconed_ssid_record": {
"dot11.advertisedssid.probe_response" : 1,
"dot11.advertisedssid.dot11d_country" : "DE",
"dot11.advertisedssid.dot11e_qbss" : 0,
"dot11.advertisedssid.ht_mode" : "HT20",
"dot11.advertisedssid.beacon" : 1,
"dot11.advertisedssid.beacon_info" : "AP-EG-01",
},
"dot11.device.supported_channels" : [],
"dot11.device.wps_m3_last" : 0,
"dot11.device.last_sequence" : 0,
"dot11.device.beacon_fingerprint" : 566256114,
"dot11.device.datasize" : 0
},
"kismet.device.base.num_alerts" : 0,
"kismet.device.base.seenby" : [
{
"kismet.common.seenby.num_packets" : 507,
"kismet.common.seenby.uuid" : "5FE308BD-0000-0000-0000-ACED5C6F85D8",
"kismet.common.seenby.signal" : {
"kismet.common.signal.min_noise" : 0,
"kismet.common.signal.encodingset": 1,
"kismet.common.signal.last_signal": -79,
"kismet.common.signal.max_signal" : -73,
"kismet.common.signal.max_noise" : 0,
"kismet.common.signal.last_noise" : 0,
"kismet.common.signal.min_signal" : -82,
"kismet.common.signal.type" : "dbm",
"kismet.common.signal.carrierset" : 1,
"kismet.common.signal.maxseenrate": 10,
},
"kismet.common.seenby.freq_khz_map": {
"2447000": 17,
"2457000": 10,
"2452000": 480
},
"kismet.common.seenby.last_time" : 1580395086,
"kismet.common.seenby.first_time" : 1580390436
}
],
"kismet.device.base.packets.crypt" : 0,
"kismet.device.base.freq_khz_map" : {
"2447000": 17,
"2457000": 10,
"2452000": 480
},
"kismet.device.base.manuf" : "Cisco Systems Inc."
}
Die Objekte „kismet.device.base.XXX“ kann ich problemlos auswerten. Problematisch wird es bei den „Unterobjekten“ ab „dot11.device“, die sich wieder in Unterobjekte aufteilen.
Hier interessiert mich speziell das Objekt "dot11.advertisedssid.ht_mode".
Könnt Ihr mir einen Tipp geben, wie ich an diese Objekte komme?
Anbei mein Code:
Code: Alles auswählen
#sqlite = 0
#JSON_Parse = 1
UseSQLiteDatabase()
Procedure count_ap()
ap.s = "SELECT * FROM devices where type='Wi-Fi AP'"
DatabaseQuery(#sqlite, ap)
While NextDatabaseRow(#sqlite)
Debug #CRLF$
first_time.i = GetDatabaseLong(#sqlite, 0)
device_info.s = GetDatabaseString(#sqlite, 14)
;Debug "Device info: " + device_info.s
;########### JSON ###########
ParseJSON(0, device_info.s)
Debug "Type: " + GetJSONString(GetJSONMember(JSONValue(0), "kismet.device.base.type"))
Debug "Device manufaturer: " + GetJSONString(GetJSONMember(JSONValue(0), "kismet.device.base.manuf"))
Debug "MAC from json: " + GetJSONString(GetJSONMember(JSONValue(0), "kismet.device.base.macaddr"))
Debug "SSID: " + GetJSONString(GetJSONMember(JSONValue(0), "kismet.device.base.name"))
Debug "Crypto: " + GetJSONString(GetJSONMember(JSONValue(0), "kismet.device.base.crypt"))
Debug "Channel: " + GetJSONString(GetJSONMember(JSONValue(0), "kismet.device.base.channel"))
Debug "Frequency: " + GetJSONInteger(GetJSONMember(JSONValue(0), "kismet.device.base.frequency"))
If ExamineJSONMembers(JSONValue(0))
While NextJSONMember(JSONValue(0))
Debug "Member: " + JSONMemberKey(JSONValue(0))
If JSONMemberKey(JSONValue(0)) = "dot11.device"
Debug "Hier sollten jetzt weitere JSONMembers / Unterobjekte stehen"
EndIf
Wend
EndIf
Wend
FinishDatabaseQuery(#sqlite)
ProcedureReturn sum_ap
EndProcedure
Filename$ = "Kismet-20200130-13-19-44-1.kismet"
If OpenDatabase(#sqlite, Filename$, "", "")
count_ap()
EndIf
CloseDatabase(#sqlite)
netzer