-
Notifications
You must be signed in to change notification settings - Fork 7
/
fetcher_stopforumspamIP.py
41 lines (34 loc) · 1.12 KB
/
fetcher_stopforumspamIP.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import urllib, zipfile, cStringIO, os, json
import re
from pymemcache.client import Client
feedaddr = 'http://www.stopforumspam.com/downloads/listed_ip_1_all.zip'
zipfilename = 'listed_ip_1_all.txt'
feedID = 'stopforumspam'
mkey = 'fetcher_stopforumspamIP:feeddata'
killchain = 'unknown'
client = Client(('localhost', 11211))
result = client.get(mkey)
if isinstance(result, str):
splitlines = result.split('\n')
else:
if os.path.isfile(zipfilename): os.remove(zipfilename)
zipwebfile = urllib.urlopen(feedaddr)
buffer = cStringIO.StringIO(zipwebfile.read())
zfile = zipfile.ZipFile(buffer)
myfile = zfile.extract('listed_ip_1_all.txt')
f = open(zipfilename, 'r')
splitlines = f.read()
client.set(mkey, splitlines, expire=7200)
splitlines = splitlines.split('\n')
if os.path.isfile(zipfilename): os.remove(zipfilename)
seen = []
print('ipv4,feedID,killchain,description')
for x in splitlines:
x = x.strip()
x = re.sub('"', '', x)
x = re.sub(',.*$', '', x)
if not re.search('^\d', x): continue
if len(x) == 0: continue
if x in seen: continue
seen.append(x)
print("%s,%s,%s,%s" % (x, feedID, killchain, 'Malicious IP'))