Added Local IPv4 address support

This commit is contained in:
EnumDev 2024-08-23 14:32:26 +03:00
parent 0fd198d83e
commit e8a95e5313
3 changed files with 15 additions and 0 deletions

View File

@ -34,6 +34,7 @@ for i in $(seq ${MOUNTED_PARTITIONS}); do
fi
fi
done
echo -e "${C3}Local IPv4 Address: ${C4}${LOCAL_IPV4}"
if [ ! -z "$DISPLAY_PROTOCOL" ]; then
echo -e "${C3}Display Protocol: ${C4}${DISPLAY_PROTOCOL}"
for i in $(seq ${CONNECTED_MONITORS}); do

View File

@ -167,6 +167,7 @@ func SetupFetchEnv(showTimeTaken bool) []string {
setVariable("DISPLAY_PROTOCOL", func() string { return GetDisplayProtocol() })
setVariable("LIBC", func() string { return GetLibc() })
setVariable("INIT_SYSTEM", func() string { return GetInitSystem() })
setVariable("LOCAL_IPV4", func() string { return GetLocalIP() })
start = time.Now().UnixMilli()
monitors := getMonitorResolution()
end = time.Now().UnixMilli()

View File

@ -10,6 +10,7 @@ import (
"github.com/moby/sys/mountinfo"
"log"
"math"
"net"
"os"
"os/exec"
"path"
@ -440,6 +441,18 @@ func GetLibc() string {
return "Musl " + strings.TrimSpace(string(bytes))
}
func GetLocalIP() string {
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP.String()
}
func FormatBytes(bytes uint64) string {
var suffixes [6]string
suffixes[0] = "B"