Send local IP used to connect to server

This commit is contained in:
raul 2024-06-10 09:19:16 +02:00
parent 974ed073f5
commit 26d86a26a2
1 changed files with 5 additions and 2 deletions

View File

@ -22,6 +22,7 @@ type Client struct {
OperatingSystem string OperatingSystem string
Hostname string Hostname string
PublicIP string PublicIP string
LocalIP string
} }
type Instructions struct { type Instructions struct {
@ -58,7 +59,8 @@ func start() error {
return e return e
} }
defer conn.Close() 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 return err
} }
for { for {
@ -84,7 +86,7 @@ func getIP() (string, error) {
return ip, nil return ip, nil
} }
func sendOSInfo(conn net.Conn) error { func sendOSInfo(conn net.Conn, localIP string) error {
currentUser, err := user.Current() currentUser, err := user.Current()
if err != nil { if err != nil {
e := fmt.Errorf("Error happened getting user: %v\n", err) e := fmt.Errorf("Error happened getting user: %v\n", err)
@ -110,6 +112,7 @@ func sendOSInfo(conn net.Conn) error {
OperatingSystem: runtime.GOOS, OperatingSystem: runtime.GOOS,
Hostname: clientHostname, Hostname: clientHostname,
PublicIP: ip, PublicIP: ip,
LocalIP: localIP,
} }
enc := gob.NewEncoder(conn) enc := gob.NewEncoder(conn)