Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Let's create an IP address and subnet calculator. Often we have two sets of IP addresses/subnets, and we need to perform operations on them:
- * Subtract one set from another. For example, subtracting "192.168.1.1/32" from "0.0.0.0/0" should yield "0.0.0.0/1, 128.0.0.0/2, 224.0.0.0/3, 208.0.0.0/4, 200.0.0.0/5, 196.0.0.0/6, 194.0.0.0/7, 193.0.0.0/8, 192.0.0.0/9, 192.192.0.0/10, 192.128.0.0/11, 192.176.0.0/12, 192.160.0.0/13, 192.172.0.0/14, 192.170.0.0/15, 192.169.0.0/16, 192.168.128.0/17, 192.168.64.0/18, 192.168.32.0/19, 192.168.16.0/20, 192.168.8.0/21, 192.168.4.0/22, 192.168.2.0/23, 192.168.0.0/24, 192.168.1.128/25, 192.168.1.64/26, 192.168.1.32/27, 192.168.1.16/28, 192.168.1.8/29, 192.168.1.4/30, 192.168.1.2/31, 192.168.1.0/32".
- * Combine (merge) the two sets, optimizing the result as much as possible.
- * Find intersections.
- Let's implement this calculator as a simple HTML page, entirely in JavaScript!
- We need two input fields for subnet sets. Subnets should be accepted in multiple formats:
- * Just an IP address (e.g., "192.168.5.6")
- * IP address with mask length (e.g., "192.168.5.0/24")
- * IP address with subnet mask (e.g., "192.168.5.0/255.255.255.0")
- Allow input of multiple subnets separated by commas or spaces.
- Provide options to choose the operation type (subtract, merge, intersect) and select output format.
- IPv4 only.
Advertisement