Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save snorfsneflin/33bb57dd028346085671 to your computer and use it in GitHub Desktop.
Save snorfsneflin/33bb57dd028346085671 to your computer and use it in GitHub Desktop.
Regex to match on only valid IPs including local and bcast
grep -E -o '(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)' file.txt
# match addresses formatted as IP/bits - e.g. 192.168.0.1/24
ip addr sh eth0 | grep -E -o "([0-9]+.){3}[0-9]+/[0-9]+"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment