Skip to content
Snippets Groups Projects
Select Git revision
  • 46ad2794f1bde3bb8b788cd099f6da3485fdcf87
  • master default protected
  • pymilter-1.0.4
  • pymilter-1.0.3
  • pymilter-1.0.2
  • pymilter-1.0.1
  • pymilter-1_0
  • milter-0_8_18
  • pymilter-0_9_8
  • pymilter-0_9_7
  • pymilter-0_9_6
  • pymilter-0_9_5
  • pymilter-0_9_4
  • pymilter-0_9_2
  • pymilter-0_9_1
  • pymilter-0_9_0
  • pymilter-0_8_12
  • pymilter-0_8_11
  • pymilter-0_8_10
  • pymilter-0_8_9
  • milter-0_8_8
  • milter-0_8_7
22 results

rejects.py

Blame
  • rejects.py 972 B
    # Analyze milter log to find abusers
    
    fp = open('/var/log/milter/milter.log','r')
    subdict = {}
    ipdict = {}
    spamcnt = {}
    for line in fp:
      a = line.split(None,4)
      if len(a) < 4: continue
      dt,tm,id,op = a[:4]
      if op == 'Subject:':
        if len(a) > 4: subdict[id] = a[4].rstrip()
      elif op == 'connect':
        ipdict[id] = a[4].rstrip()
      elif op in ('eom','dspam'):
        if id in subdict: del subdict[id]
        if id in ipdict: del ipdict[id]
      elif op in ('REJECT:','DSPAM:','SPAM:','abort'):
        if id in subdict:
          if id in ipdict:
            ip = ipdict[id]
    	del ipdict[id]
    	f,host,raw = ip.split(None,2)
    	if host in spamcnt:
    	  spamcnt[host] += 1
    	else:
    	  spamcnt[host] = 1
          else: ip = ''
          print dt,tm,op,a[4].rstrip(),subdict[id]
          del subdict[id]
        else:
          print line.rstrip()
    print len(subdict),'leftover entries'
    
    spamlist = filter(lambda x: x[1] > 1,spamcnt.items())
    spamlist.sort(lambda x,y: x[1] - y[1])
    for ip,cnt in spamlist:
      print cnt,ip