mirror of
https://github.com/pavel-odintsov/fastnetmon
synced 2024-11-24 02:46:36 +01:00
Add stub for firewall queue implementation
This commit is contained in:
parent
a80f0b44f2
commit
0d2440160d
36
src/exabgp_queue_writer.py
Normal file
36
src/exabgp_queue_writer.py
Normal file
@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
from redis import Redis
|
||||
from rq import Queue
|
||||
|
||||
exabgp_log = open("/tmp/exabgp.log", "a")
|
||||
|
||||
import firewall_queue
|
||||
|
||||
q = Queue(connection=Redis())
|
||||
|
||||
while True:
|
||||
try:
|
||||
line = sys.stdin.readline().strip()
|
||||
# print >> sys.stderr, "GOT A LINE"
|
||||
|
||||
sys.stdout.flush()
|
||||
if line == "":
|
||||
counter += 1
|
||||
if counter > 100:
|
||||
break
|
||||
continue
|
||||
|
||||
counter = 0
|
||||
|
||||
q.enqueue(firewall_queue.execute_ip_ban, line)
|
||||
exabgp_log.write(line + "\n")
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except IOError:
|
||||
# most likely a signal during readline
|
||||
pass
|
||||
|
8
src/firewall_queue.py
Normal file
8
src/firewall_queue.py
Normal file
@ -0,0 +1,8 @@
|
||||
from subprocess import call
|
||||
|
||||
def execute_ip_ban(ip):
|
||||
print "Will ban IP: " + ip + "\n"
|
||||
call(["iptables", "-A", "INPUT", "-s", ip, "-j", "DROP"])
|
||||
return True
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user