Last active
May 16, 2016 21:46
-
-
Save lanrat/0b2a952b4bff329fc3b124e3e0d1cf9d to your computer and use it in GitHub Desktop.
docker-proxy ipv6
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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