From 26d86a26a239b395f6e0a1e6b71c7a81557da0d9 Mon Sep 17 00:00:00 2001 From: raul Date: Mon, 10 Jun 2024 09:19:16 +0200 Subject: [PATCH] Send local IP used to connect to server --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 6d7ca7c..768df4f 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,7 @@ type Client struct { OperatingSystem string Hostname string PublicIP string + LocalIP string } type Instructions struct { @@ -58,7 +59,8 @@ func start() error { return e } defer conn.Close() - if err := sendOSInfo(conn); err != nil { + localIP := fmt.Sprint(conn.LocalAddr().(*net.TCPAddr).IP) + if err := sendOSInfo(conn, localIP); err != nil { return err } for { @@ -84,7 +86,7 @@ func getIP() (string, error) { return ip, nil } -func sendOSInfo(conn net.Conn) error { +func sendOSInfo(conn net.Conn, localIP string) error { currentUser, err := user.Current() if err != nil { e := fmt.Errorf("Error happened getting user: %v\n", err) @@ -110,6 +112,7 @@ func sendOSInfo(conn net.Conn) error { OperatingSystem: runtime.GOOS, Hostname: clientHostname, PublicIP: ip, + LocalIP: localIP, } enc := gob.NewEncoder(conn)