Exemplo n.º 1
0
    def ios_to_networks(self, fp_in, lat, lon):
        """Reads in iOS scan file and serializes to JSON"""
        self.log.info('opening: {}'.format(fp_in))
        location = pd.read_csv(fp_in,
                               comment='#',
                               skipinitialspace=True,
                               quotechar='"')

        location['SSID'] = location['SSID'].fillna('')  # hidden or empty SSIDs

        networks = {}
        for i, scan in location.iterrows():
            bssid = scan['BSSID']
            ssid = str(scan['SSID'])
            if not ssid or ssid == '':
                ssid = str(''.join(
                    random.choice(ascii_uppercase) for i in range(6)))
            rssi = int(scan['RSSI'])
            if bssid in networks.keys():
                # update RSSI if higher
                networks[bssid].rssi = max(networks[bssid].rssi, rssi)
            else:
                net = WiFiNet(ssid, bssid, scan['Channel'], rssi, lat, lon)
                networks[bssid] = net

        networks_list = [v.serialize() for k, v in networks.items()]
        return networks_list
Exemplo n.º 2
0
    def wigle_export_to_networks(self, fp_in, fp_out, comment):
        '''Reads Wigle export CSV and generates network list
    '''
        df_scan = pd.read_csv(fp_in, skiprows=(1))
        df_scan['SSID'] = df_scan['SSID'].fillna('')  # hidden or empty SSIDs

        networks = {}
        for i, scan in df_scan.iterrows():
            bssid = scan['MAC']
            if not len(bssid) == 17:
                continue  # not a WiFi network
            ssid = str(scan['SSID'])
            lat = scan['CurrentLatitude']
            lon = scan['CurrentLongitude']
            if not ssid or ssid == '':
                ssid = str(''.join(
                    random.choice(ascii_uppercase)
                    for i in range(6)))  # random SSID
            rssi = int(scan['RSSI'])
            if bssid in networks.keys():
                networks[bssid].rssi = max(networks[bssid].rssi,
                                           rssi)  # update max RSSI
            else:
                net = WiFiNet(ssid, bssid, scan['Channel'], rssi, lat, lon)
                networks[bssid] = net

        networks_list = [v.serialize() for k, v in networks.items()]
        return networks_list
Exemplo n.º 3
0
    def fetch(self, url, lat, lon):
        """Downloads WiFi data from Wigle API
      Requires API Name/Token
      """
        # https://api.wigle.net/api/v2/network/search?onlymine=false&latrange1=34.09368&latrange2=34.097456&longrange1=-118.380996&longrange2=-118.376404&lastupdt=20160101&freenet=false&paynet=false

        networks = []
        target = (lat, lon)

        # authenticate and get JSON
        # self.log.info('making GET request: {}'.format(url))
        wigle_data = requests.get(url,
                                  headers={'Authentication': 'Basic'},
                                  auth=(self.api_name, self.api_token))

        # parse wigle results into JSON file
        try:
            wigle_data = wigle_data.json()['results']
        except:
            self.log.error('could not parse data: {}'.format(wigle_data))
            self.log.error(wigle_data)
            self.log.error(f'url: {url}')
            return []

        for n in wigle_data:
            actual = (n['trilat'], n['trilong'])
            rssi_estimated = geo_utils.calc_geo_rssi(actual, target)
            wifi_net = WiFiNet(n['ssid'],
                               n['netid'],
                               n['channel'],
                               rssi=rssi_estimated,
                               qos=n['qos'],
                               lat=n['trilat'],
                               lon=n['trilong'],
                               lat_target=lat,
                               lon_target=lon)
            networks.append(wifi_net)

        # serialize network data
        networks = [n.serialize() for n in networks]
        self.log.debug(f'Found {len(networks)} networks')
        return networks