/ ctiger / dataframe.py
dataframe.py
 1  # Copyright (c) 2024 Anoduck
 2  # 
 3  # This software is released under the MIT License.
 4  # https://opensource.org/licenses/MIT
 5  
 6  import os
 7  import pandas as pd
 8  import csv
 9  from warnings import warn
10  
11  
12  class CtigerDataFrame:
13  
14      def load_apnetworks(self, netdb_file, log) -> pd.DataFrame:
15          self.netdb_file = netdb_file
16          self.log = log
17          log.debug('netdb_file type: {0}'.format(type(netdb_file)))
18          if os.path.isfile(netdb_file):
19              log.info('Loading networks from: {}'.format(netdb_file))
20              network_df = pd.DataFrame(columns=['SSID', 'Mac', 'Crypto',
21                                                 'Channel', 'Last Update',
22                                                 'Latitude', 'Longitude'])
23              network_df.set_index("SSID", inplace=True)
24              netdict = csv.DictReader(open(netdb_file), delimiter=',')
25              # SSID,NetID,Encryption,Channel,Last Update,Latitude,Longitude
26              for entry in netdict:
27                  if entry.get('SSID') == '':
28                      BSSID = entry.get('NetID')
29                      entry['SSID'] = BSSID
30                  network_df.loc[entry['SSID']] = [entry['NetID'], entry['Encryption'], entry['Channel'], entry['Last Update'], entry['Latitude'], entry['Longitude']]
31              return network_df
32          else:
33              warn(message='Could not load file', category=None, stacklevel=1)
34              exit(1)
35  
36      def load_df(self, valid_file, log):
37          self.valid_file = valid_file
38          if os.path.exists(valid_file):
39              log.info('Loading valid targets from: {}'.format(valid_file))
40              targets = pd.read_csv(valid_file, index_col=0)
41              devices = targets.index.to_list()
42              return devices
43          else:
44              log.info('No valid targets found')
45              return None
46  
47      def get_df(self):
48          """
49          Initializes a new empty DataFrame for storing scan data.
50  
51          Returns:
52              pandas.DataFrame: The newly created DataFrame with columns 'BSSID', 'SSID', 'dBm_Signal', 'Channel', and 'Crypto'.
53          """
54          scan_df = pd.DataFrame(columns=['BSSID', 'SSID',
55                                          'dBm_Signal', 'Channel',
56                                          'Crypto'])
57          scan_df.set_index("BSSID", inplace=True)
58          return scan_df