-
Notifications
You must be signed in to change notification settings - Fork 8
/
01_firewall_simulator.py
33 lines (28 loc) · 1019 Bytes
/
01_firewall_simulator.py
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
import random
def generate_random_ip():
"""Generate a random IP address."""
return f"192.168.1.{random.randint(0, 20)}"
def check_firewall_rules(ip, rules):
"""Check if the IP address matches any firewall rule and return the action."""
for rule_ip, action in rules.items():
if ip == rule_ip:
return action
return "allow" # Default action if no rule matches
def main():
# Define the firewall rules (key: IP address, value: action)
firewall_rules = {
"192.168.1.1": "block",
"192.168.1.4": "block",
"192.168.1.9": "block",
"192.168.1.13": "block",
"192.168.1.16": "block",
"192.168.1.19": "block"
}
# Simulate network traffic
for _ in range(12):
ip_address = generate_random_ip()
action = check_firewall_rules(ip_address, firewall_rules)
random_number = random.randint(0, 9999)
print(f"IP: {ip_address}, Action: {action}, Random: {random_number}")
if __name__ == "__main__":
main()