Last active
December 7, 2018 08:41
-
-
Save sonyarianto/38f78b7d8357f0acadc51fc6ceac5356 to your computer and use it in GitHub Desktop.
Get local IP address
This file contains 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() { | |
conn, err := net.Dial("udp", "8.8.8.8:80") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer conn.Close() | |
localAddr := conn.LocalAddr().(*net.UDPAddr) | |
fmt.Println(localAddr.IP) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment