canihazip/canihazip.go

22 lines
438 B
Go
Raw Normal View History

2024-04-11 17:45:14 -06:00
package main
import (
"fmt"
"net"
"net/http"
)
func getMyIP(w http.ResponseWriter, r *http.Request) {
host, _, _ := net.SplitHostPort(r.RemoteAddr)
fmt.Fprint(w, host)
fmt.Printf("Received request from %s\n", host)
}
func main() {
fmt.Println("Server running on 0.0.0.0:5000")
http.HandleFunc("/", getMyIP)
if err := http.ListenAndServe("0.0.0.0:5000", nil); err != nil {
panic(err)
}
}