This script helps generate security group rules based on a list of IP ranges.
It accepts several command-line arguments for configuration.
argparse
ipaddress
| Argument | Aliases | Default | Description |
|---|---|---|---|
--source |
--src |
ips.txt |
Source file containing IP ranges. |
--export |
--exp |
rules.txt |
Export file where generated rules will be saved. |
--direction |
inbound |
Direction of the traffic (inbound or outbound). |
|
--protocol |
TCP |
Protocol to use (TCP or UDP). |
|
--ports |
None | Port range(s) in valid iptables syntax (e.g., 22, 53, 80:90, 110, 1024:65535). |
|
--name |
My SG |
Name of the Security Group. |
173.245.48.0/20
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
141.101.64.0/18
108.162.192.0/18
190.93.240.0/20
RULE=[
IP="173.245.48.1",
PROTOCOL="TCP",
RANGE="22,80",
RULE_TYPE="inbound",
SIZE="4094" ]
RULE=[
IP="103.21.244.1",
PROTOCOL="TCP",
RANGE="22,80",
RULE_TYPE="inbound",
SIZE="1022" ]
RULE=[
IP="103.22.200.1",
PROTOCOL="TCP",
RANGE="22,80",
RULE_TYPE="inbound",
SIZE="1022" ]
RULE=[
IP="103.31.4.1",
PROTOCOL="TCP",
RANGE="22,80",
RULE_TYPE="inbound",
SIZE="1022" ]
RULE=[
IP="141.101.64.1",
PROTOCOL="TCP",
RANGE="22,80",
RULE_TYPE="inbound",
SIZE="16382" ]
RULE=[
IP="108.162.192.1",
PROTOCOL="TCP",
RANGE="22,80",
RULE_TYPE="inbound",
SIZE="16382" ]
RULE=[
IP="190.93.240.1",
PROTOCOL="TCP",
RANGE="22,80",
RULE_TYPE="inbound",
SIZE="4094" ]
NAME="Web SG"
python builder.py --source ips.txt --export rules.txt --direction inbound --protocol TCP --ports 22,80 --name "Web SG"
onesecgroup create rules.txt