From 74c0a215edc7dde1bd29b8f1f3f370958e26f811 Mon Sep 17 00:00:00 2001 From: mountain Date: Thu, 22 Jun 2023 20:17:30 +0900 Subject: [PATCH] =?UTF-8?q?noauth=EC=9D=84=20=EB=95=8C=20=EC=82=AC?= =?UTF-8?q?=EC=84=A4=20IP=EB=8C=80=EC=97=AD=EB=A7=8C=20=ED=97=88=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/maingate.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/maingate.go b/core/maingate.go index 4893a6f..0c565a8 100644 --- a/core/maingate.go +++ b/core/maingate.go @@ -430,6 +430,23 @@ func whitelistKey(email string) string { return email } +func isPrivateIP(ip net.IP) bool { + if ip[0] == 10 { + return true + } + + if ip[0] == 172 { + if ip[1] >= 16 && ip[1] < 32 { + return true + } + return false + } + + if ip[0] == 192 && ip[1] == 168 { + return true + } + return false +} func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMux, prefix string) error { var allServices []*serviceDescription @@ -443,7 +460,7 @@ func (mg *Maingate) RegisterHandlers(ctx context.Context, serveMux *http.ServeMu ipaddr := "127.0.0.1" for _, addr := range addrs { if ipnet, ok := addr.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { - if ipnet.IP.To4() != nil { + if ipnet.IP.To4() != nil && ipnet.IP.IsPrivate() { ipaddr = ipnet.IP.String() } }