Skip to content

Instantly share code, notes, and snippets.

@jniltinho
Created March 26, 2014 17:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jniltinho/9788121 to your computer and use it in GitHub Desktop.
Save jniltinho/9788121 to your computer and use it in GitHub Desktop.
Get External IP Golang
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)
}
@alexandrevilain
Copy link

@colecrouter
Copy link

Note: is "https://myexternalip.com/raw" now, no longer "http".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment