cybersecurity · intermediate · ~15 min · safe pentest lab
Recognise the RFC1918 private ranges.
Recognise the RFC 1918 private ranges — the only addresses a home lab should ever target.
Implement int is_private_ip(int a, int b) that returns 1 if an address whose first two octets are a.b is in a private range, else 0.
Private ranges (based on the first two octets):
10.x (first octet 10)192.168.x (192 then 168)172.16.x .. 172.31.x (172 then 16..31)a, b: the first and second octets of the address. The grader passes fixed values.Returns int: 1 if a.b falls in a private range, else 0.
is_private_ip(10, 0) -> 1
is_private_ip(192, 168) -> 1
is_private_ip(172, 20) -> 1
is_private_ip(8, 8) -> 0 (public)
is_private_ip(172, 15) -> 0 (just outside 172.16-31)
172 is private only when the second octet is 16..31.The first two octets a, b of an address.
An int: 1 if a.b is in a private (RFC 1918) range, else 0.
10.x; 192.168.x; 172.16-31.x; second octet matters for 172.
int is_private_ip(int a, int b) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.