26 lines
542 B
Go
26 lines
542 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"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() {
|
|
port := flag.String("port", "5000", "port to listen on")
|
|
flag.Parse()
|
|
|
|
fmt.Printf("== Server running on 0.0.0.0:%s ==\n", *port)
|
|
http.HandleFunc("/", getMyIP)
|
|
if err := http.ListenAndServe("0.0.0.0:"+*port, nil); err != nil {
|
|
panic(err)
|
|
}
|
|
}
|