(essid, capfile)
return ''
Returns first BSSID of access point found in cap file.
        This is not accurate at all, but it's a good guess.
        Returns '' if not found.
Returns first BSSID of access point found in cap file.
        This is not accurate at all, but it's a good guess.
        Returns '' if not found.
Returns first BSSID of access point found in cap file . This is not accurate at all but it s a good guess . Returns if not found .
def get_bssid_from_cap(essid, capfile):
    """
        Returns first BSSID of access point found in cap file.
        This is not accurate at all, but it's a good guess.
        Returns '' if not found.
    """
    global RUN_CONFIG
    
    if not program_exists('tshark'): return ''

# Attempt to get BSSID based on ESSID
    if essid != '':
        cmd = ['tshark',
               '-r', capfile,
               '-R', 'wlan_mgt.ssid == "%s" && wlan.fc.type_subtype == 0x05' % (essid),
               '-n',            # Do not resolve MAC vendor names
               '-T', 'fields',  # Only display certain fields
               '-e', 'wlan.sa'] # souce MAC address
        proc = Popen(cmd, stdout=PIPE, stderr=DN)
        proc.wait()
        bssid = proc.communicate()[0].split('\n')[0]
        if bssid != '': return bssid
    
    cmd = ['tshark',
           '-r', capfile,
           '-R', 'eapol',
           '-n']
    proc = Popen(cmd, stdout=PIPE, stderr=DN)
    proc.wait()
    for line in proc.communicate()[0].split('\n'):
        if line.endswith('Key (msg 1/4)') or line.endswith('Key (msg 3/4)'):
            while line.startswith(' ') or line.startswith('\t'): line = line[1:]
            line = line.replace('\t', ' ')
            while line.find('  ') != -1: line = line.replace('  ', ' ')
            return line.split(' ')[2]
        elif line.endswith('Key (msg 2/4)') or line.endswith('Key (msg 4/4)'):
            while line.startswith(' ') or line.startswith('\t'): line = line[1:]
            line = line.replace('\t', ' ')
            while line.find('  ') != -1: line = line.replace('  ', ' ')
            return line.split(' ')[4]
    return ''
def get_bssid_from_cap ( essid , capfile ) : global RUN_CONFIG if not program_exists ( 'tshark' ) : return '' # Attempt to get BSSID based on ESSID if essid != '' : cmd = [ 'tshark' , '-r' , capfile , '-R' , 'wlan_mgt.ssid == "%s" && wlan.fc.type_subtype == 0x05' % ( essid ) , '-n' , # Do not resolve MAC vendor names '-T' , 'fields' , # Only display certain fields '-e' , 'wlan.sa' ] # souce MAC address proc = Popen ( cmd , stdout = PIPE , stderr = DN ) proc . wait ( ) bssid = proc . communicate ( ) [ 0 ] . split ( '\n' ) [ 0 ] if bssid != '' : return bssid cmd = [ 'tshark' , '-r' , capfile , '-R' , 'eapol' , '-n' ] proc = Popen ( cmd , stdout = PIPE , stderr = DN ) proc . wait ( ) for line in proc . communicate ( ) [ 0 ] . split ( '\n' ) : if line . endswith ( 'Key (msg 1/4)' ) or line . endswith ( 'Key (msg 3/4)' ) : while line . startswith ( ' ' ) or line . startswith ( '\t' ) : line = line [ 1 : ] line = line . replace ( '\t' , ' ' ) while line . find ( '  ' ) != - 1 : line = line . replace ( '  ' , ' ' ) return line . split ( ' ' ) [ 2 ] elif line . endswith ( 'Key (msg 2/4)' ) or line . endswith ( 'Key (msg 4/4)' ) : while line . startswith ( ' ' ) or line . startswith ( '\t' ) : line = line [ 1 : ] line = line . replace ( '\t' , ' ' ) while line . find ( '  ' ) != - 1 : line = line . replace ( '  ' , ' ' ) return line . split ( ' ' ) [ 4 ] return ''