new security tasks
This commit is contained in:
31
files/subnet_check/ip_check.py
Normal file
31
files/subnet_check/ip_check.py
Normal file
@ -0,0 +1,31 @@
|
||||
import yaml
|
||||
import argparse
|
||||
from ipaddress import IPv4Network, IPv4Address
|
||||
|
||||
def load_subnet_list(file_path):
|
||||
with open(file_path, 'r') as file:
|
||||
data = yaml.safe_load(file)
|
||||
return [str(net) for net in data['subnet_list']]
|
||||
|
||||
def check_ip_in_subnets(ip, subnet_list):
|
||||
ip_address = IPv4Address(ip)
|
||||
for subnet in subnet_list:
|
||||
if ip_address in IPv4Network(subnet):
|
||||
return True
|
||||
return False
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Check if an IP address is within a list of subnets.")
|
||||
parser.add_argument("ip", type=str, help="The IP address to check")
|
||||
args = parser.parse_args()
|
||||
|
||||
subnet_list = load_subnet_list('subnets.yaml')
|
||||
result = check_ip_in_subnets(args.ip, subnet_list)
|
||||
|
||||
if result:
|
||||
print("True")
|
||||
else:
|
||||
print("False")
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
2
files/subnet_check/requirements.txt
Normal file
2
files/subnet_check/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
pyyaml
|
||||
ipaddress
|
||||
7
files/subnet_check/subnets.yaml
Normal file
7
files/subnet_check/subnets.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
subnet_list:
|
||||
- "172.20.0.0/16"
|
||||
- "172.25.1.0/24"
|
||||
|
||||
...
|
||||
Reference in New Issue
Block a user