Created
March 26, 2014 17:02
-
-
Save jniltinho/9788121 to your computer and use it in GitHub Desktop.
Get External IP Golang
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 | |
/* | |
URL: http://myexternalip.com/#golang | |
*/ | |
import ( | |
"io" | |
"net/http" | |
"os" | |
) | |
func main() { | |
resp, err := http.Get("http://myexternalip.com/raw") | |
if err != nil { | |
os.Stderr.WriteString(err.Error()) | |
os.Stderr.WriteString("\n") | |
os.Exit(1) | |
} | |
defer resp.Body.Close() | |
io.Copy(os.Stdout, resp.Body) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For ip v4, use : http://ipv4.myexternalip.com/raw