mirror of
https://codeberg.org/prof_x_pvt_ltd/captive.whump.shanti-portal
synced 2024-08-14 22:46:42 +00:00
started on python wrapper to add clients.
This commit is contained in:
parent
7380c9a41d
commit
5005498d05
1 changed files with 30 additions and 0 deletions
30
tools/add_client.py
Normal file
30
tools/add_client.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
from pprint import pprint as pp
|
||||||
|
|
||||||
|
import iptc
|
||||||
|
|
||||||
|
parser = ArgumentParser()
|
||||||
|
|
||||||
|
parser.add_argument('--chain', required=True)
|
||||||
|
parser.add_argument('--protocol', required=True)
|
||||||
|
parser.add_argument('--src-ip', required=True)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
table = iptc.Table(iptc.Table.MANGLE)
|
||||||
|
chain = iptc.Chain(table, args.chain)
|
||||||
|
|
||||||
|
# Check if rule exists
|
||||||
|
for rule in chain.rules:
|
||||||
|
src_ip = rule.src
|
||||||
|
if src_ip.startswith(args.src_ip):
|
||||||
|
print('Rule exists')
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
rule = iptc.Rule()
|
||||||
|
rule.src = args.src_ip
|
||||||
|
rule.protocol = args.protocol
|
||||||
|
rule.target = iptc.Target(rule, 'RETURN')
|
||||||
|
chain.insert_rule(rule)
|
Loading…
Reference in a new issue