Ip address

2 snippets across 2 stacks — Bash & Linux, Regular Expressions

Also written as IP address

SHBash & Linux

View & Configure Network Interfaces

SH · Networking
syntax
ip addr show
ifconfig
example
ip addr show eth0
ip route show
ifconfig en0
output
2: eth0: <BROADCAST,MULTICAST,UP> mtu 1500
    inet 192.168.1.42/24 brd 192.168.1.255 scope global eth0

Note ip is the modern Linux tool; ifconfig is legacy but still default on macOS. 'ip addr' shows addresses, 'ip route' shows the routing table, 'ip link' manages interfaces. On macOS, the primary interface is usually en0.

RXRegular Expressions

IPv4 Address

RX · Common Patterns
syntax
/\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/
example
JS:  '192.168.1.1 and 999.999.999.999'.match(/\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b/g)
Py:  re.findall(r'\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b', text)
output
["192.168.1.1"]  (999.999.999.999 rejected -- octets must be 0-255)

Note Each octet allows 0-255. The alternation order matters: check 25[0-5] before 2[0-4]\d before the general case. A simpler but less accurate version is \d{1,3}(\.\d{1,3}){3} which does not validate octet ranges.