From e8a95e5313e465fb0c1e12718c62ef1ccd868d55 Mon Sep 17 00:00:00 2001 From: EnumDev Date: Fri, 23 Aug 2024 14:32:26 +0300 Subject: [PATCH] Added Local IPv4 address support --- config/fetch_script.sh | 1 + main.go | 1 + utils.go | 13 +++++++++++++ 3 files changed, 15 insertions(+) diff --git a/config/fetch_script.sh b/config/fetch_script.sh index 2c47bbe..c0d8c29 100644 --- a/config/fetch_script.sh +++ b/config/fetch_script.sh @@ -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 diff --git a/main.go b/main.go index afc730f..cec56ab 100644 --- a/main.go +++ b/main.go @@ -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() diff --git a/utils.go b/utils.go index c0cfcf3..6981a8f 100644 --- a/utils.go +++ b/utils.go @@ -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"