Created
May 23, 2019 01:46
-
-
Save mingcheng/2c384f971b0fc09ded03865c9f437dfe to your computer and use it in GitHub Desktop.
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 ( | |
| "fmt" | |
| "log" | |
| "net" | |
| ) | |
| func main() { | |
| addrs, err := net.InterfaceAddrs() | |
| if err != nil { | |
| log.Fatal(err) | |
| } | |
| for _, address := range addrs { | |
| if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { | |
| if ipnet.IP.To4() != nil { | |
| fmt.Println(ipnet.IP.String()) | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment