From 622a36b015c84c944036af8cd6904b744448eb1c Mon Sep 17 00:00:00 2001 From: techflashYT Date: Thu, 21 Mar 2024 13:24:06 -0700 Subject: [PATCH] use blacklist for interface names This allows the code to not need to specify every possible interface name, which would get out of hand very quickly. --- src/main.go | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main.go b/src/main.go index fd1fae4..39ad80e 100644 --- a/src/main.go +++ b/src/main.go @@ -60,16 +60,6 @@ func main() { Aliases: []string{"l"}, Usage: "get local IP address information", Action: func(cCtx *cli.Context) error { - validNames := []string{ - // Local Interfaces - "en0", - "eth0", - - // Tunnel Addresses - "wg0", - "utun10", - } - ifaces, err := net.Interfaces() if err != nil { fmt.Print(fmt.Errorf("localAddresses: %+v\n", err.Error())) @@ -93,10 +83,8 @@ func main() { fmt.Println(color.MagentaString("LOCAL INTERFACES:")) for _, i := range ifaces { - if contains(validNames, i.Name) == false { - continue - } - + if i.Name == "lo" { continue } + if len(i.Name) >= 6 && i.Name[:6] == "docker" { continue } var v4Addr string var v6Addr string