Skip to content

Commit b2bb326

Browse files
committed
Fixed private ip lookup
Signed-off-by: Vishal Rana <[email protected]>
1 parent 3336020 commit b2bb326

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
IMAGE = labstack/armor
2-
VERSION = 0.4.9
2+
VERSION = 0.4.10
33

44
run:
55
go run cmd/armor/main.go

armor.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ type (
9292
)
9393

9494
const (
95-
Version = "0.4.9"
95+
Version = "0.4.10"
9696
Website = "https://armor.labstack.com"
9797
)
9898

http.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func (h *HTTP) Start() error {
9999
e := h.echo
100100
if a.DefaultConfig {
101101
a.Colorer.Printf("⇨ serving from %s (Local)\n", a.Colorer.Green("http://localhost"+a.Address))
102-
ip := util.GetPrivateIP()
102+
ip := util.PrivateIP()
103103
if ip != "" {
104104
_, port, _ := net.SplitHostPort(a.Address)
105105
a.Colorer.Printf("⇨ serving from %s (Intranet)\n", a.Colorer.Green(fmt.Sprintf("http://%s:%s", ip, port)))

util/util.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,22 @@ func StripPort(host string) string {
2424
return host[:colon]
2525
}
2626

27-
func GetPrivateIP() string {
27+
func PrivateIP() string {
2828
addrs, err := net.InterfaceAddrs()
2929
if err != nil {
3030
return ""
3131
}
3232
for _, address := range addrs {
3333
if ipNet, ok := address.(*net.IPNet); ok && !ipNet.IP.IsLoopback() {
3434
if ipNet.IP.To4() != nil {
35-
return ipNet.IP.String()
35+
ip := ipNet.IP
36+
_, cidr24BitBlock, _ := net.ParseCIDR("10.0.0.0/8")
37+
_, cidr20BitBlock, _ := net.ParseCIDR("172.16.0.0/12")
38+
_, cidr16BitBlock, _ := net.ParseCIDR("192.168.0.0/16")
39+
private := cidr24BitBlock.Contains(ip) || cidr20BitBlock.Contains(ip) || cidr16BitBlock.Contains(ip)
40+
if private {
41+
return ip.String()
42+
}
3643
}
3744
}
3845
}

website/content/guide.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ Type `armor` in your terminal
4444
___
4545
/ _ | ______ _ ___ ____
4646
/ __ |/ __/ ' \/ _ \/ __/
47-
/_/ |_/_/ /_/_/_/\___/_/ v0.4.9
47+
/_/ |_/_/ /_/_/_/\___/_/ v0.4.10
4848
4949
Uncomplicated, modern HTTP server
5050
https://armor.labstack.com

0 commit comments

Comments
 (0)