Congratulations, you're now a network administrator! As your first task you will need to configure a firewall to stop any traffic to some blacklisted addresses.
Unfortunately, the only firewall at your disposal only takes in rules in this format:
x.y.z.t/m ALLOW
There's no DENY
keyword. If you want to exclude a specific address, you'll have to write a lot of rules to allow everything except that address. If you want to exclude more than one address or a whole range, then you're in luck because these ALLOW
rules will overlap to some degree.
The challenge
You are given a list of blacklisted IPs. Write a program that will print out rules for our firewall. Also, be sensible when writing rules: don't just enumerate all 256^4 and don't print out duplicates.
Code golf rules apply: shortest code wins
*this problem is inspired by a real life assignment; a friend actually needed this done
Example
To block address 0.1.2.3 you could write the following ALLOW
rules (this is not the only solution possible, and it's certainly not the shortest):
0.1.2.0 ALLOW
0.1.2.1 ALLOW
0.1.2.2 ALLOW
0.1.2.4 ALLOW
...
0.1.2.255 ALLOW
0.1.0.0/24 ALLOW
0.1.1.0/24 ALLOW
0.1.4.0/24 ALLOW
...
0.1.255.0/24 ALLOW
0.0.0.0/16 ALLOW
0.2.0.0/16 ALLOW
...
0.255.0.0/16 ALLOW
1.0.0.0/8 ALLOW
...
255.0.0.0/8 ALLOW