dev.net
IP addresses, address blocks and subnets, and which service uses which port
IP addresses and blocks of them, as used when setting up networks.
writing
Section titled “writing”A block of addresses is written in CIDR notation, like 10.0.0.0/22. The number after the slash says how many of the 32 bits at the start are fixed, and the rest can be anything, so a /22 holds 2 to the power of 10, or 1024 addresses, and a /24 holds 256. The first address in a block names the network itself and the last is the broadcast address that reaches every machine on it, so neither can be given to a single machine.
Tags: network
ipan IPv4 or IPv6 address as a plain integer, or an integer back as an addresscidrfacts about an IPv4 block like “10.0.0.0/22”in_cidrwhether an IPv4 address is inside a block like “10.0.0.0/22”subnetssplit an IPv4 block into smaller blocks with the given prefix length, so a /22 splits into four /24sip_kindwhat an address is forportthe service that normally listens on a port number, like “ssh” for 22, or the port for a service name, or nil if unknown
Functions
Section titled “Functions”ip(s: str) -> int / ip(n: int) -> str
an IPv4 or IPv6 address as a plain integer, or an integer back as an address
An IPv4 address like 192.168.1.5 is really a 32-bit number written as four bytes, so this lets you do arithmetic on addresses
1ip("192.168.1.5")32322357812ip(3232235781)"192.168.1.5"3ip("::1")1cidr(s: str) -> map
facts about an IPv4 block like “10.0.0.0/22”
Its network and broadcast addresses, netmask, the first and last address a machine can use, and how many there are (hosts)
1cidr("192.168.1.77/26"){network: "192.168.1.64", broadcast: "192.168.1.127", netmask: "255.255.255.192", prefix: 26, first: "192.168.1.65", last: "192.168.1.126", hosts: 62}in_cidr
Section titled “in_cidr”in_cidr(ip: str, block: str) -> bool
whether an IPv4 address is inside a block like “10.0.0.0/22”
1in_cidr("10.0.3.7", "10.0.0.0/22")trueSee also cidr
subnets
Section titled “subnets”subnets(block: str, prefix: int) -> list
split an IPv4 block into smaller blocks with the given prefix length, so a /22 splits into four /24s
1subnets("10.0.0.0/24", 26)["10.0.0.0/26", "10.0.0.64/26", "10.0.0.128/26", "10.0.0.192/26"]See also cidr
ip_kind
Section titled “ip_kind”ip_kind(ip: str) -> str
what an address is for
“loopback” (this machine), “private” (a home or office network), “link-local” (self-assigned when there’s no router), “multicast”, “unspecified” (0.0.0.0) or “public”
1ip_kind("10.1.2.3")"private"2ip_kind("8.8.8.8")"public"See also ip
port(n: int) -> str|nil / port(name: str) -> int|nil
the service that normally listens on a port number, like “ssh” for 22, or the port for a service name, or nil if unknown
1port(22)"ssh"2port("postgresql")5432See also http_status, ip
More examples
Section titled “More examples”1# how many machines fit in a /222cidr("10.0.0.0/22").hosts10223# is it in the block?4in_cidr("10.0.3.7", "10.0.0.0/22")true5# an address as bits6ip("192.168.1.5") to bin0b110000001010100000000001000001017# the address after 10.0.0.2558ip(ip("10.0.0.255") + 1)"10.0.1.0"9# split into /24s10subnets("10.0.0.0/22", 24)["10.0.0.0/24", "10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]11# what runs on 5432?12port(5432)"postgresql"Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.