cybersecurity · beginner · ~15 min · safe pentest lab

Is it a safe lab target?

Combine loopback and private checks for lab safety.

Challenge

Decide whether an address is safe to practise against: only loopback or your own private lab network.

Task

Implement int lab_safe(int a, int b, int c, int d) that returns 1 if the address a.b.c.d is loopback or private, else 0.

Safe when:

  • loopback: first octet 127, OR
  • private: 10.x, 192.168.x, or 172.16-31.x.

Input

  • a, b, c, d: the four octets of the address. The grader passes fixed values (only a and b affect the result).

Output

Returns int: 1 if the address is loopback or private, else 0.

Example

lab_safe(127, 0, 0, 1)    ->   1   (loopback)
lab_safe(192, 168, 1, 5)  ->   1   (private)
lab_safe(1, 1, 1, 1)      ->   0   (public)

Edge cases

  • Any public address returns 0 — never a safe lab target.

Rules

  • Reuse the loopback + private-range logic; pure arithmetic.

Input format

The four octets a, b, c, d of an address.

Output format

An int: 1 if the address is loopback or private, else 0.

Constraints

Loopback 127.x or private (10.x / 192.168.x / 172.16-31.x).

Starter code

int lab_safe(int a, int b, int c, int d) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.