def get_ip(self): """ Get the IP address of the interface. Returns: The IP address of the interface in dotted quad form. """ cmd = "%s %s" % (misc.find_program_in_path("ifconfig"), self.interface_name) output = misc.run(cmd) return misc.run_regex(InterfaceRegexPatterns.ip, output)
def _parse_access_point(self, cell): """ Parse a single cell from the output of iwlist. Keyword arguments: cell -- string containing the cell information Returns: A dictionary containing the cell networks properties. """ ap = WirelessNetwork() ap.essid = misc.run_regex(WirelessRegexPatterns.essid, cell) try: ap.essid = misc.to_unicode(ap.essid) except (UnicodeDecodeError, UnicodeEncodeError): logging.debug('Unicode problem with current network essid, ignoring!!') return None if ap.essid in ['<hidden>', ""]: ap.essid = 'Hidden' ap.hidden = True else: ap.hidden = False ap.channel = misc.run_regex(WirelessRegexPatterns.channel, cell) if ap.channel == None: freq = misc.run_regex(WirelessRegexPatterns.freq, cell) ap.channel = self._freq_to_channel(freq) ap.bssid = misc.run_regex(WirelessRegexPatterns.ap_mac, cell) ap.mode = misc.run_regex(WirelessRegexPatterns.mode, cell) if (WirelessRegexPatterns.strength.match(cell)): [(strength, max_strength)] = WirelessRegexPatterns.strength.findall(cell) if max_strength: ap.quality = 100 * int(strength) // int(max_strength) else: ap.quality = int(strength) elif misc.run_regex(WirelessRegexPatterns.altstrength,cell): ap.quality = misc.run_regex(WirelessRegexPatterns.altstrength, cell) else: ap.quality = -1 if misc.run_regex(WirelessRegexPatterns.signaldbm, cell): ap.strength = misc.run_regex(WirelessRegexPatterns.signaldbm, cell) return ap