#!/usr/bin/env python3

import socket
import struct
import sys


def cidr(addr, sz):
    mask = (0xFFFFFFFF >> sz) ^ 0xFFFFFFFF
    (addr_n,) = struct.unpack("!I", socket.inet_aton(addr))
    base = socket.inet_ntoa(struct.pack("!I", addr_n & mask))
    return f"{base}/{sz}"


def main():
    if len(sys.argv) != 3:
        print("Two arguments required, IP and CIDR range.", file=sys.stderr)
        return 2
    print(cidr(sys.argv[1], int(sys.argv[2])))
    return 0


if __name__ == "__main__":
    sys.exit(main())
