Skip to content

Instantly share code, notes, and snippets.

@lanrat
Last active May 16, 2016 21:46
Show Gist options
  • Save lanrat/0b2a952b4bff329fc3b124e3e0d1cf9d to your computer and use it in GitHub Desktop.
Save lanrat/0b2a952b4bff329fc3b124e3e0d1cf9d to your computer and use it in GitHub Desktop.
docker-proxy ipv6
package main
//
// Run with:
// docker run -it --rm -p 8000:8000 -v $(pwd):/data debian /data/ip
//
import (
"fmt"
"net"
"io"
"net/http"
)
func getIpAddress(r *http.Request) string {
hdrRealIp, _, _ := net.SplitHostPort(r.RemoteAddr)
return hdrRealIp
}
func hello(w http.ResponseWriter, r *http.Request) {
ip := getIpAddress(r)
fmt.Println(ip)
io.WriteString(w, ip+"\n")
}
func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8000", nil)
}
user@host:~$ curl -4 http://domain.tld:8000/
137.***.***.3
user@host:~$ curl -6 http://domain.tld:8000/
172.17.42.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment