Python read ip address and if over 10 attempts save to file called failed.py
<p>Hey I am currently trying to make a program basically if ip addresses have over 10 attempts then to save them to a file called failed.py</p>

<p>Here the code I got so far</p>

<pre><code>myFile = open('auth','r')

ips = {}

for line in myFile:
    parts = line.split(' ')
    if parts[3] == 'authentication failure':
        if parts[3] in ips:
            ips[parts[0]] += 1
        else:
            ips[parts[0]] = 0

with open('failed.py','w') as myFile:
    for ip in [k for k, v in ips.iteritems() if v &gt;=10]:
        myFile.write(ip)
</code></pre>

<p>Here example of file trying to read from</p>

<pre><code>Jan 10 09:32:07 j4-be03 sshd[3876]: pam_unix(sshd:auth): authentication failure;    logname= uid=0 euid=0 tty=ssh ruser= rhost=218.241.173.35  user=root
Jan 10 09:32:09 j4-be03 sshd[3876]: Failed password for root from 218.241.173.35 port 47084 ssh2
</code></pre>
