Created
June 24, 2019 16:32
-
-
Save vadviktor/a7256dbaf262e1a108c2032d28a35aac to your computer and use it in GitHub Desktop.
Find IP address that matches a subset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "bytes" | |
| "fmt" | |
| "log" | |
| "net" | |
| ) | |
| func main() { | |
| ifaces, err := net.Interfaces() | |
| if err != nil { | |
| log.Print(fmt.Errorf("localAddresses: %v\n", err.Error())) | |
| return | |
| } | |
| for _, i := range ifaces { | |
| addrs, err := i.Addrs() | |
| if err != nil { | |
| log.Print(fmt.Errorf("localAddresses: %v\n", err.Error())) | |
| continue | |
| } | |
| for _, a := range addrs { | |
| switch v := a.(type) { | |
| case *net.IPNet: | |
| needle := []byte(`10.7.7.`) | |
| hay := []byte(v.IP.String()) | |
| if bytes.Contains(hay, needle) { | |
| log.Println("YES") | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment