(target, capfile)
return False
Uses TShark to check for a handshake.
        Returns "True" if handshake is found, false otherwise.
Uses TShark to check for a handshake.
        Returns "True" if handshake is found, false otherwise.
Uses TShark to check for a handshake . Returns True if handshake is found false otherwise .
def has_handshake_tshark(target, capfile):
    """
        Uses TShark to check for a handshake.
        Returns "True" if handshake is found, false otherwise.
    """
    if program_exists('tshark'):
        # Call Tshark to return list of EAPOL packets in cap file.
        cmd = ['tshark',
               '-r', capfile, # Input file
               '-R', 'eapol', # Filter (only EAPOL packets)
               '-n']          # Do not resolve names (MAC vendors)
        proc = Popen(cmd, stdout=PIPE, stderr=DN)
        proc.wait()
        lines = proc.communicate()[0].split('\n')
        
        # Get list of all clients in cap file
        clients = []
        for line in lines:
            if line.find('appears to have been cut short') != -1 or line.find('Running as user "root"') != -1 or line.strip() == '':
                continue
            
            while line.startswith(' '):  line = line[1:]
            while line.find('  ') != -1: line = line.replace('  ', ' ')
            
            fields = line.split(' ')
            src = fields[2].lower()
            dst = fields[4].lower()
            
            if src == target.bssid.lower() and clients.count(dst) == 0: clients.append(dst)
            elif dst == target.bssid.lower() and clients.count(src) == 0: clients.append(src)
        
        # Check each client for a handshake
        for client in clients:
            msg_num = 1 # Index of message in 4-way handshake (starts at 1)
            
            for line in lines:
                if line.find('appears to have been cut short') != -1: continue
                if line.find('Running as user "root"') != -1: continue
                if line.strip() == '': continue
                
                # Sanitize tshark's output, separate into fields
                while line[0] == ' ': line = line[1:]
                while line.find('  ') != -1: line = line.replace('  ', ' ')
                
                fields = line.split(' ')
                
                # Sometimes tshark doesn't display the full header for "Key (msg 3/4)" on the 3rd handshake.
                # This catches this glitch and fixes it.
                if len(fields) < 8: 
                    continue
                elif len(fields) == 8:
                    fields.append('(msg')
                    fields.append('3/4)')
                
                src = fields[2].lower() # Source MAC address
                dst = fields[4].lower() # Destination MAC address
                #msg = fields[9][0]      # The message number (1, 2, 3, or 4)
                msg = fields[-1][0]
                
                # First, third msgs in 4-way handshake are from the target to client
                if msg_num % 2 == 1 and (src != target.bssid.lower() or dst != client): continue
                # Second, fourth msgs in 4-way handshake are from client to target
                elif msg_num % 2 == 0 and (dst != target.bssid.lower() or src != client): continue
                
                # The messages must appear in sequential order.
                try:
                    if int(msg) != msg_num: continue
                except ValueError: continue
                
                msg_num += 1
                
                # We need the first 4 messages of the 4-way handshake
                # Although aircrack-ng cracks just fine with only 3 of the messages...
                if msg_num >= 4:
                    return True
    return False
def has_handshake_tshark ( target , capfile ) : if program_exists ( 'tshark' ) : # Call Tshark to return list of EAPOL packets in cap file. cmd = [ 'tshark' , '-r' , capfile , # Input file '-R' , 'eapol' , # Filter (only EAPOL packets) '-n' ] # Do not resolve names (MAC vendors) proc = Popen ( cmd , stdout = PIPE , stderr = DN ) proc . wait ( ) lines = proc . communicate ( ) [ 0 ] . split ( '\n' ) # Get list of all clients in cap file clients = [ ] for line in lines : if line . find ( 'appears to have been cut short' ) != - 1 or line . find ( 'Running as user "root"' ) != - 1 or line . strip ( ) == '' : continue while line . startswith ( ' ' ) : line = line [ 1 : ] while line . find ( '  ' ) != - 1 : line = line . replace ( '  ' , ' ' ) fields = line . split ( ' ' ) src = fields [ 2 ] . lower ( ) dst = fields [ 4 ] . lower ( ) if src == target . bssid . lower ( ) and clients . count ( dst ) == 0 : clients . append ( dst ) elif dst == target . bssid . lower ( ) and clients . count ( src ) == 0 : clients . append ( src ) # Check each client for a handshake for client in clients : msg_num = 1 # Index of message in 4-way handshake (starts at 1) for line in lines : if line . find ( 'appears to have been cut short' ) != - 1 : continue if line . find ( 'Running as user "root"' ) != - 1 : continue if line . strip ( ) == '' : continue # Sanitize tshark's output, separate into fields while line [ 0 ] == ' ' : line = line [ 1 : ] while line . find ( '  ' ) != - 1 : line = line . replace ( '  ' , ' ' ) fields = line . split ( ' ' ) # Sometimes tshark doesn't display the full header for "Key (msg 3/4)" on the 3rd handshake. # This catches this glitch and fixes it. if len ( fields ) < 8 : continue elif len ( fields ) == 8 : fields . append ( '(msg' ) fields . append ( '3/4)' ) src = fields [ 2 ] . lower ( ) # Source MAC address dst = fields [ 4 ] . lower ( ) # Destination MAC address #msg = fields[9][0]      # The message number (1, 2, 3, or 4) msg = fields [ - 1 ] [ 0 ] # First, third msgs in 4-way handshake are from the target to client if msg_num % 2 == 1 and ( src != target . bssid . lower ( ) or dst != client ) : continue # Second, fourth msgs in 4-way handshake are from client to target elif msg_num % 2 == 0 and ( dst != target . bssid . lower ( ) or src != client ) : continue # The messages must appear in sequential order. try : if int ( msg ) != msg_num : continue except ValueError : continue msg_num += 1 # We need the first 4 messages of the 4-way handshake # Although aircrack-ng cracks just fine with only 3 of the messages... if msg_num >= 4 : return True return False