package main import ( "fmt" "net" "net/http" ) func init() { http.HandleFunc("/ip", ip) } func ip(w http.ResponseWriter, r *http.Request) { addr, _, err := net.SplitHostPort(r.RemoteAddr) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } fmt.Fprintln(w, addr) host, err := net.LookupAddr(addr) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } fmt.Fprintln(w, host) }