-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbanip.py
More file actions
59 lines (51 loc) · 1.62 KB
/
banip.py
File metadata and controls
59 lines (51 loc) · 1.62 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
# _____ ___ ______ _____ __ _______ _ _
#/ ___|/ _ \ | ___| ___| \ \ / / _ | | | |
#\ `--./ /_\ \| |_ | |__ \ V /| | | | | | |
# `--. \ _ || _| | __| \ / | | | | | | |
#/\__/ / | | || | | |___ | | \ \_/ / |_| |
#\____/\_| |_/\_| \____/ \_/ \___/ \___/
#
# Prevention attack DDoS
import sys
import getopt
import subprocess
_name = "SafeYOU BANIP"
_version = "1.0"
def main(argv):
try:
opts, args = getopt.getopt(argv, "ha:d:lv", ["help", "add=", "delete=", "list", "version"])
if len(opts) == 0:
if len(args) > 0:
opts = []
for arg in args:
opts.append(("-a", arg))
else:
opts = [("-h","")]
for opt, arg in opts:
if opt in ("-h", "--help"):
aide()
elif opt in ("-a", "--add"):
subprocess.call(["iptables", "-A", "INPUT", "-s", arg, "-j", "DROP"])
elif opt in ("-d", "--delete"):
subprocess.call(["iptables", "-D", "INPUT", "-s", arg, "-j", "DROP"])
elif opt in ("-l", "--list"):
subprocess.call(["iptables", "-L", "-n"])
except getopt.GetoptError as err:
print("IPban error: " + str(err))
sys.exit(2)
except:
print("IPban error (unknown).")
sys.exit(2)
def version():
global _name, _version
return _name + " " + _version
def aide():
print(version())
print("Utilisation : ipban [ips|-h|-a ip|-d ip|-l]\n")
print("-h Affiche ce message.")
print("-a Ajoute une adresse IP à la liste de blocage. Exemple: 1.2.3.4")
print("-d Supprime une adresse IP de la liste de blocage. Exemple: 1.2.3.4")
print("-l Les règles iptables appliquées.")
if __name__ == "__main__":
main(sys.argv[1:])