Some code reorg

This commit is contained in:
yo
2022-04-24 16:55:33 +02:00
parent 43f26d099f
commit e4fc9c3a6c
4 changed files with 50 additions and 43 deletions

View File

@ -4,6 +4,8 @@ import (
"fmt"
"golang.org/x/net/route"
"net"
"regexp"
"strings"
)
var defaultRoute4 = [4]byte{0, 0, 0, 0}
@ -103,3 +105,22 @@ func (jh *JailHost) GetDefaultGateway6() string {
}
return jh.default_gateway6
}
func getHostInUseIPv4() ([]string, error) {
var ips []string
re := regexp.MustCompile(ifconfigipv4re)
out, err := executeCommand("/sbin/ifconfig")
if err != nil {
return ips, fmt.Errorf("ERROR executing \"/sbin/ifconfig\": %s", err)
}
for _, line := range strings.Split(out, "\n") {
if re.MatchString(line) {
ips = append(ips, re.FindStringSubmatch(line)[1])
}
}
return ips, nil
}