]> git.ipfire.org Git - ipfire-3.x.git/commitdiff
Did a small rewrite of ids-block script.
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 21 Jan 2009 20:48:29 +0000 (21:48 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 21 Jan 2009 20:48:29 +0000 (21:48 +0100)
config/syslog-ng/ids-block

index ad4b74445a1d4ee65ba8a2373986078915cd78a3..9d411c2e49f87fe8f2771660d52e9f1d266c8bf5 100644 (file)
@@ -1,14 +1,47 @@
 #!/usr/bin/python
+###############################################################################
+#                                                                             #
+# IPFire.org - A linux based firewall                                         #
+# Copyright (C) 2007, 2008, 2009 Michael Tremer & Christian Schmidt           #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+###############################################################################
 
-import sys,os,re
-#print sys.argv
+import os
+import sys
+import re
 
-if len(sys.argv) < 2:
-       print 'Es wurden keine Parameter uebergeben.'
-       sys.exit()
+from IPy import IP
 
 #os.system('modprobe ipt_recent ip_list_tot=1000')
 
-m = re.findall(r"[1-9]{1,1}[0-9]{0,2}\.[1-9]{1,1}[0-9]{0,2}\.[1-9]{1,1}[0-9]{0,2}\.[1-9]{1,1}[0-9]{0,2}", sys.argv[1])
-#print m
-os.system('echo %s > /proc/net/ipt_recent/BLOCK' % m[0])
+try:
+       ip = IP(sys.argv[1])
+except KeyError:
+       sys.stderr.write("Not enough parameters given.\n")
+       sys.exit(1)
+except ValueError:
+       sys.stderr.write("Given value is not a valid ip address.\n")
+       sys.exit(1)
+
+try:
+       f = open("/proc/net/ipt_recent/BLOCK", "w")
+       f.write("%s\n" % ip)
+       f.close()
+except:
+       sys.stderr.write("Cannot write ip \"%s\" to file.\n" % ip)
+       sys.exit(1)
+
+sys.exit(0)