def getNetworksAsJson(interfaceName, gpsData, huntChannelList=None): # This is only used by the remote agent to get and return networks if (huntChannelList is None) or (len(huntChannelList) == 0): # This code handles the thought that "what if we query for networks and the interface # reports busy (it does happen if we query too fast.) retries = 0 retCode = WirelessNetwork.ERR_DEVICEBUSY while (retCode == WirelessNetwork.ERR_DEVICEBUSY) and (retries < 3): # Handle retries in case we get a busy response retCode, errString, wirelessNetworks = WirelessEngine.scanForNetworks(interfaceName) retries += 1 if retCode == WirelessNetwork.ERR_DEVICEBUSY: sleep(0.4) else: wirelessNetworks = {} for curFrequency in huntChannelList: # Handle if the device reports busy with some retries retries = 0 retCode = WirelessNetwork.ERR_DEVICEBUSY while (retCode == WirelessNetwork.ERR_DEVICEBUSY) and (retries < 3): # Handle retries in case we get a busy response retCode, errString, tmpWirelessNetworks = WirelessEngine.scanForNetworks(interfaceName,curFrequency ) retries += 1 if retCode == WirelessNetwork.ERR_DEVICEBUSY: sleep(0.2) for curKey in tmpWirelessNetworks.keys(): curNet = tmpWirelessNetworks[curKey] wirelessNetworks[curNet.getKey()] = tmpWirelessNetworks[curNet.getKey()] retVal = {} retVal['errCode'] = retCode retVal['errString'] = errString netList = [] for curKey in wirelessNetworks.keys(): curNet = wirelessNetworks[curKey] if gpsData is not None: curNet.gps.copy(gpsData) netList.append(curNet.toJsondict()) gpsdict = {} gpsloc = SparrowGPS() if (gpsData is not None): gpsloc.copy(gpsData) gpsdict['latitude'] = gpsloc.latitude gpsdict['longitude'] = gpsloc.longitude gpsdict['altitude'] = gpsloc.altitude gpsdict['speed'] = gpsloc.speed retVal['gps'] = gpsdict retVal['networks'] = netList jsonstr = json.dumps(retVal) return retCode, errString, jsonstr
def __init__(self): self.macAddr = "" self.ssid = "" self.mode = "" # master, managed, monitor, etc. self.security = "Open" # on or off self.privacy = "None" # group cipher self.cipher = "" # pairwise cipher self.channel = 0 # Channel # self.frequency = 0 self.signal = -1000 # dBm self.stationcount = -1 self.utilization = -1.0 self.bandwidth = 20 # Default to 20. we'll bump it up as we see params. max BW in any protocol 20 or 40 or 80 or 160 MHz self.secondaryChannel = 0 # used for 40+ MHz self.thirdChannel = 0 # used for 80+ MHz channels self.secondaryChannelLocation = '' # above/below now=datetime.datetime.now() self.firstSeen = now self.lastSeen = now self.gps = SparrowGPS() self.strongestsignal = self.signal self.strongestgps = SparrowGPS() # Used for tracking in network table self.foundInList = False super().__init__()
def getNetworksAsJson(self, gpsData): # This reads the scan file airodumpcsvfile = '/dev/shm/falconairodump-01.csv' retVal = {} retVal['errCode'] = 0 retVal['errString'] = '' if os.path.isfile(airodumpcsvfile): networks, clients = FalconWirelessEngine.parseAiroDumpCSV(airodumpcsvfile) errCode = 0 errmsg = '' else: errCode = 1 errmsg = 'Temp scan file not found. Scan may not be running.' retVal['errCode'] = errCode retVal['errString'] = errmsg networks = {} clients = {} netList = [] if networks: for curKey in networks.keys(): curNet = networks[curKey] if gpsData is not None: curNet.gps.copy(gpsData) netList.append(curNet.toJsondict()) clientList = [] if clients: for curKey in clients.keys(): curClient = clients[curKey] if gpsData is not None: curClient.gps.copy(gpsData) clientList.append(curClient.toJsondict()) gpsdict = {} gpsloc = SparrowGPS() if (gpsData is not None): gpsloc.copy(gpsData) gpsdict['latitude'] = gpsloc.latitude gpsdict['longitude'] = gpsloc.longitude gpsdict['altitude'] = gpsloc.altitude gpsdict['speed'] = gpsloc.speed retVal['gps'] = gpsdict retVal['networks'] = netList retVal['clients'] = clientList jsonstr = json.dumps(retVal) return errCode, errmsg, jsonstr
def __init__(self): self.macAddr = "" self.apMacAddr = "" self.ssid = "" self.channel = 0 self.signal = -1000 # dBm now=datetime.datetime.now() self.firstSeen = now self.lastSeen = now self.gps = SparrowGPS() self.strongestsignal = self.signal self.strongestgps = SparrowGPS() self.probedSSIDs = [] # Used for tracking in network table self.foundInList = False
def __init__(self): self.uuid="" self.macAddress = "" self.name="" self.company="" self.manufacturer="" self.bluetoothDescription = "" self.btType = BluetoothDevice.BT_LE # Classic or low energy self.rssi=-100 self.txPower = -60 self.txPowerValid = False self.iBeaconRange = -1.0 self.firstSeen = datetime.datetime.now() self.lastSeen = datetime.datetime.now() self.gps = SparrowGPS() self.strongestRssi = self.rssi self.strongestgps = SparrowGPS() self.foundInList = False
class BluetoothDevice(object): BT_CLASSIC = 1 BT_LE = 2 def __init__(self): self.uuid="" self.macAddress = "" self.name="" self.company="" self.manufacturer="" self.bluetoothDescription = "" self.btType = BluetoothDevice.BT_LE # Classic or low energy self.rssi=-100 self.txPower = -60 self.txPowerValid = False self.iBeaconRange = -1.0 self.firstSeen = datetime.datetime.now() self.lastSeen = datetime.datetime.now() self.gps = SparrowGPS() self.strongestRssi = self.rssi self.strongestgps = SparrowGPS() self.foundInList = False def __str__(self): retVal = "" retVal += "UUID: " + self.uuid + '\n' retVal += "Address: " + self.macAddress + '\n' retVal += "Company: " + self.company + '\n' retVal += "Manufacturer: " + self.manufacturer + '\n' if self.btType == BluetoothDevice.BT_CLASSIC: retVal += 'btType: Bluetooth Classic\n' else: retVal += 'btType: Bluetooth Low Energy (BTLE)\n' retVal += "Bluetooth Description: " + self.bluetoothDescription + '\n' retVal += "RSSI: " + str(self.rssi) + '\n' retVal += "TX Power: " + str(self.txPower) + '\n' retVal += "TX Power Valid: " + str(self.txPowerValid) + '\n' retVal += "Estimated Range (m): " + str(self.iBeaconRange) + '\n' retVal += "Strongest RSSI: " + str(self.strongestRssi) + '\n' retVal += "Last GPS:\n" retVal += str(self.gps) retVal += "Strongest GPS:\n" retVal += str(self.strongestgps) return retVal def __eq__(self, obj): # This is equivance.... == if not isinstance(obj, BluetoothDevice): return False if self.uuid != obj.uuid: return False if self.macAddress != obj.macAddress: return False if self.btType != obj.btType: return False return True def __ne__(self, other): return not self.__eq__(other) def copy(self, other): self.uuid=other.uuid self.macAddress = other.macAddress self.name=other.name self.company=other.company self.manufacturer=other.manufacturer self.bluetoothDescription = other.bluetoothDescription self.btType = other.btType self.rssi=other.rssi self.txPower = other.txPower self.txPowerValid = other.txPowerValid self.iBeaconRange = other.iBeaconRange self.firstSeen = other.firstSeen self.lastSeen = other.lastSeen self.gps.copy(other.gps) self.strongestRssi = other.strongestRssi self.strongestgps.copy(other.strongestgps) self.foundInList = False def getKey(self): key = self.macAddress # + "_" + str(self.btType) return key def calcRange(self): if not self.txPowerValid or self.txPower == 0: self.iBeaconRange = -1 return # This is what iOS does: # https://stackoverflow.com/questions/20416218/understanding-ibeacon-distancing # Also note: "accuracy" is iOS's terminology for distance #ratio = self.rssi / self.txPower #if ratio < 1.0: # self.iBeaconRange = ratio ** 10 #else: # self.iBeaconRange = 0.89976* (ratio ** 7.7095) + 0.111 #self.iBeaconRange = round(self.iBeaconRange, 2) try: ratio_db = float(self.txPower - self.rssi) # txPower is supposed to be the RSSI measured at 1m. # In reality that's not quite what I've observed. # txPower may be a default/guess so watch the math. # Generally rssi < txPower making ratio_db >= 0 if ratio_db < 0.0: self.iBeaconRange = 0.0 return elif ratio_db <= 1.5: self.iBeaconRange = 0.5 return elif ratio_db <= 3.0: self.iBeaconRange = 1.0 return #n = 3 # free space n = 2, real-world range is 2.7 - 4.3 # If we don't have an rssi, this could calc wrong #dist = 10 ** (ratio_db / (10*n)) dist = 10.0 ** (ratio_db / 10.0) # Safety check on sqrt if dist < 0.0: dist = 0.0 dist = math.sqrt(dist) self.iBeaconRange = round(dist, 2) except: self.iBeaconRange = -1 # Old: #try: # txPower = int(strTxPower) # ratio_db = float(txPower - rssi) # If we don't have an rssi, this could calc wrong # ratio_linear = 10.0 ** ( ratio_db / 10.0 ) # if ratio_linear >= 0.0: # dist = round(math.sqrt(ratio_linear), 2) # else: # dist = -1.0 #except: # dist = -1.0 #try: # txPower = int(strTxPower) # gain = 5 # FSPL unknown gain factor # path_loss = math.fabs(float(txPower - rssi)) + gain # If we don't have an rssi, this could calc wrong # Calc is based on free space path loss at 2.4ish MHz (freq matters) # http://www.electronicdesign.com/communications/understanding-wireless-range-calculations # dist = 10.0 ** ( (path_loss - 32.44 - 67.78) / 20.0 ) * 1000.0 # dist = round(dist, 2) #except: # dist = -1 def fromJson(self, jsonstr): dictjson = json.loads(jsonstr) self.fromJsondict(dictjson) def toJson(self): dictjson = self.toJsondict() return json.dumps(dictjson) def fromJsondict(self, dictjson): # Note: if the json dictionary isn't correct, this will naturally throw an exception that may # need to be caught for error detection self.uuid = dictjson['uuid'] self.macAddress = dictjson['macAddr'] self.name = dictjson['name'] self.company = dictjson['company'] self.manufacturer = dictjson['manufacturer'] self.bluetoothDescription = dictjson['bluetoothdescription'] self.btType = int(dictjson['bttype']) self.rssi = int(dictjson['rssi']) self.txPower = int(dictjson['txpower']) self.txPowerValid = stringtobool(dictjson['txpowervalid']) self.strongestRssi = int(dictjson['strongestrssi']) self.iBeaconRange = float(dictjson['ibeaconrange']) self.firstSeen = parser.parse(dictjson['firstseen']) self.lastSeen = parser.parse(dictjson['lastseen']) self.gps.latitude = float(dictjson['lat']) self.gps.longitude = float(dictjson['lon']) self.gps.altitude = float(dictjson['alt']) self.gps.speed = float(dictjson['speed']) self.gps.isValid = stringtobool(dictjson['gpsvalid']) self.strongestgps.latitude = float(dictjson['strongestlat']) self.strongestgps.longitude = float(dictjson['strongestlon']) self.strongestgps.altitude = float(dictjson['strongestalt']) self.strongestgps.speed = float(dictjson['strongestspeed']) self.strongestgps.isValid = stringtobool(dictjson['strongestgpsvalid']) def toJsondict(self): dictjson = {} dictjson['type'] = 'bluetooth' dictjson['uuid'] = self.uuid dictjson['macAddr'] = self.macAddress dictjson['name'] = self.name dictjson['company'] = self.company dictjson['manufacturer'] = self.manufacturer dictjson['bluetoothdescription'] = self.bluetoothDescription dictjson['bttype'] = self.btType dictjson['rssi'] = self.rssi dictjson['txpower'] = self.txPower dictjson['txpowervalid'] = str(self.txPowerValid) dictjson['strongestrssi'] = self.strongestRssi dictjson['ibeaconrange'] = self.iBeaconRange dictjson['firstseen'] = str(self.firstSeen) dictjson['lastseen'] = str(self.lastSeen) dictjson['lat'] = str(self.gps.latitude) dictjson['lon'] = str(self.gps.longitude) dictjson['alt'] = str(self.gps.altitude) dictjson['speed'] = str(self.gps.speed) dictjson['gpsvalid'] = str(self.gps.isValid) dictjson['strongestlat'] = str(self.strongestgps.latitude) dictjson['strongestlon'] = str(self.strongestgps.longitude) dictjson['strongestalt'] = str(self.strongestgps.altitude) dictjson['strongestspeed'] = str(self.strongestgps.speed) dictjson['strongestgpsvalid'] = str(self.strongestgps.isValid) return dictjson