如何从 Go 检查网页是从 localhost 还是从外部访问?
如何禁用外部用户的某些功能?
如何隐藏整个站点,例如“不,这里什么都没有,端口 8080 已关闭,继续前进”。
问问题
1584 次
1 回答
6
To check if website is accessed from outside, check remote IP address. If it is not from 127.0.0.1 or ::1 (IPv6) then it is outside. Use function
func (*IPConn) RemoteAddr
.To disable some functions check the above condition.
To hide the whole site, bind your service to the localhost interface (127.0.0.1) only.
Binding
net.Listen("tcp", "localhost:8080")
or
net.Listen("tcp6", "ip6-localhost:8080")
Using http package
http.ListenAndServe("localhost:8080", nil)
于 2013-08-18T11:52:18.467 回答