1
0
mirror of https://github.com/schollz/cowyo.git synced 2023-08-10 21:13:00 +03:00

Updated - websocket switches with SSL

Automatic detection of IP address (for local only)
Added binary building (not ready)
This commit is contained in:
Zack Scholl
2016-02-15 16:59:32 -05:00
parent 59cd27fca2
commit f934edc757
8 changed files with 47 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"math/rand"
"net"
"path"
"sort"
"strings"
@@ -216,3 +217,21 @@ func RandStringBytesMaskImprSrc(n int) string {
return string(b)
}
// GetLocalIP returns the local ip address
func GetLocalIP() string {
addrs, err := net.InterfaceAddrs()
if err != nil {
return ""
}
bestIP := ""
for _, address := range addrs {
// check the address type and if it is not a loopback the display it
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil && (strings.Contains(ipnet.IP.String(), "192.168.1") || strings.Contains(ipnet.IP.String(), "192.168")) {
return ipnet.IP.String()
}
}
}
return bestIP
}