original_docstring: 
      Parse fail2ban log for IP addresses
  
      :param: target_file - fail2ban file to search for IPs in.
      
docstring: Parse fail2ban log for IP addresses
  :param: target_file - fail2ban file to search for IPs in.
docstring_tokens: Parse fail2ban log for IP addresses : param : target_file - fail2ban file to search for IPs in .
code: def main(target_file):
      '''
      Parse fail2ban log for IP addresses
  
      :param: target_file - fail2ban file to search for IPs in.
      '''
      ip_regex = (r'\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.'
                  r'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.'
                  r'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.'
                  r'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b')
      all_matches = []
  
      # find matches and add them to array all_matches
      with open(target_file) as log:
          for line in log:
              match = re.search(ip_regex, line)
              if match:
                  all_matches.append(match.group())
  
      # get all IPs with matches equal or greater than the amount MAX_OCCURENCES
      sorted_ips = collections.Counter(all_matches)
      banned_ips = [item for item in sorted_ips if sorted_ips[item]>MAX_OCCURENCES]
      for ip in banned_ips:
          print 'Banned ' + ip
          subprocess.Popen(["iptables", "-A", "INPUT", "-s", ip, "-j", "DROP"])
code_tokens: def main ( target_file ) : ip_regex = ( r'\b(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.' r'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.' r'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.' r'(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\b' ) all_matches = [ ] with open ( target_file ) as log : for line in log : match = re . search ( ip_regex , line ) if match : all_matches . append ( match . group ( ) ) sorted_ips = collections . Counter ( all_matches ) banned_ips = [ item for item in sorted_ips if sorted_ips [ item ] > MAX_OCCURENCES ] for ip in banned_ips : print 'Banned ' + ip subprocess . Popen ( [ "iptables" , "-A" , "INPUT" , "-s" , ip , "-j" , "DROP" ] )
short_docstring: Parse fail2ban log for IP addresses
  :param: target_file - fail2ban file to search for IPs in.
short_docstring_tokens: Parse fail2ban log for IP addresses : param : target_file - fail2ban file to search for IPs in .
comment: '''
      Parse fail2ban log for IP addresses
  
      :param: target_file - fail2ban file to search for IPs in.
      '''$SEP$# find matches and add them to array all_matches$SEP$# get all IPs with matches equal or greater than the amount MAX_OCCURENCES