MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / getOutboundIP

Function getOutboundIP

internal/util/ssh_helper.go:74–91  ·  view source on GitHub ↗

getOutboundIP retrieves the preferred outbound IP address of this machine. It uses a UDP connection to a public DNS server to determine the local IP address that would be used for outbound traffic. Returns: - string: The outbound IP address as a string - error: An error if the IP address cannot be

()

Source from the content-addressed store, hash-verified

72// - string: The outbound IP address as a string
73// - error: An error if the IP address cannot be determined, nil otherwise
74func getOutboundIP() (string, error) {
75 conn, err := net.Dial("udp", "8.8.8.8:80")
76 if err != nil {
77 return "", err
78 }
79 defer func() {
80 if closeErr := conn.Close(); closeErr != nil {
81 log.Warnf("Failed to close UDP connection: %v", closeErr)
82 }
83 }()
84
85 localAddr, ok := conn.LocalAddr().(*net.UDPAddr)
86 if !ok {
87 return "", fmt.Errorf("could not assert UDP address type")
88 }
89
90 return localAddr.IP.String(), nil
91}
92
93// GetIPAddress attempts to find the best-available IP address.
94// It first tries to get the public IP address, and if that fails,

Callers 1

GetIPAddressFunction · 0.85

Calls 3

DialMethod · 0.80
CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected