mirror of
https://github.com/fail2ban/fail2ban.git
synced 2026-03-11 08:55:31 +00:00
44 lines
1.5 KiB
Python
Executable file
44 lines
1.5 KiB
Python
Executable file
#!/usr/bin/python
|
|
# This file is part of Fail2Ban.
|
|
#
|
|
# Fail2Ban 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 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Fail2Ban 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 Fail2Ban; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
# Iptable wrapper, call the right iptables depending of the ip proposed
|
|
# Author: Paul J Aka "Thanat0s"
|
|
|
|
import sys, re, subprocess
|
|
|
|
def main(argv):
|
|
regv4 = re.compile('([0-9]{1,3}\.){3}[0-9]{1,3}')
|
|
print "-" + argv + "-"
|
|
if regv4.search(argv):
|
|
# we are facing to a ipv4
|
|
subprocess.call(["iptables", argv])
|
|
sys.exit
|
|
else:
|
|
# if not, maybe it's a ipv6
|
|
regv6 = re.compile('::[A-Fa-f0-9]{1,4}|(:[A-Fa-f0-9]{1,4}){2,}')
|
|
if regv6.search(argv):
|
|
subprocess.call(["ip6tables", argv])
|
|
sys.exit
|
|
else:
|
|
# if it's not a ipv6 either, we call both iptables
|
|
subprocess.call(["iptables", argv])
|
|
subprocess.call(["ip6tables", argv])
|
|
|
|
# Main call, pass all variables
|
|
if __name__ == "__main__":
|
|
main(" ".join(sys.argv[1:]))
|