added real ip to be sent to the server
This commit is contained in:
parent
20afb2f216
commit
a6a48b8501
|
@ -12,6 +12,7 @@ import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"math"
|
"math"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"net"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
@ -31,7 +32,7 @@ type Agent struct {
|
||||||
InitialContact string `json:"initialContact"`
|
InitialContact string `json:"initialContact"`
|
||||||
LastContact string `json:"lastContact"`
|
LastContact string `json:"lastContact"`
|
||||||
AddPort string `json:"addPort"`
|
AddPort string `json:"addPort"`
|
||||||
HostName string `json:"HostName"`
|
HostName string `json:"hostName"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Message struct {
|
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 main() {
|
||||||
func StartServer(agentInteractivePort int){
|
func StartServer(agentInteractivePort int){
|
||||||
// agentInteractivePort is only needed for interactive sessions
|
// agentInteractivePort is only needed for interactive sessions
|
||||||
agentName := "Agent-001"
|
agentName := "Agent-001"
|
||||||
agentId := strconv.Itoa(randomInt(8))
|
agentId := strconv.Itoa(randomInt(8))
|
||||||
agentIp := "127.0.0.1"
|
agentIp := GetLocalIP().String()
|
||||||
agentType := "Interactive"
|
agentType := "Interactive"
|
||||||
addPort := strconv.Itoa(agentInteractivePort)
|
addPort := strconv.Itoa(agentInteractivePort)
|
||||||
hostname, _ := os.Hostname()
|
hostname, _ := os.Hostname()
|
||||||
|
|
Loading…
Reference in New Issue