From b1fb17656429f726dd1b8b8c3e1649abec1e5217 Mon Sep 17 00:00:00 2001 From: shokinn Date: Tue, 14 Jul 2026 09:45:23 +0200 Subject: [PATCH] Add ifgrep function to match network devices by IP address pattern --- dotfiles/commonfunc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dotfiles/commonfunc b/dotfiles/commonfunc index d17984d..e8ee8d3 100644 --- a/dotfiles/commonfunc +++ b/dotfiles/commonfunc @@ -204,6 +204,22 @@ addec() { } {%@@ if distro == 'macos' @@%} + +####################################### +# Shows all devices matching a given IP address Pattern. +# Globals: +# None +# Arguments: +# IP address pattern to match +# Outputs: +# Matching network device information +# Returns: +# None +####################################### +ifgrep() { + ifconfig | awk -v q="$1" '/^[^ \t]/ {if(block&&hit) print block; block=$0; hit=0; next} {block=block ORS $0} $1=="inet" && index($2,q) {hit=1} END{if(block&&hit) print block}'; +} + ####################################### # Shows a netstat -tulpn styled output on mac. # Globals: