mirror of
https://github.com/DeBrosOfficial/orama.git
synced 2026-03-17 13:06:56 +00:00
25 lines
555 B
Go
25 lines
555 B
Go
package wireguard
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
)
|
|
|
|
// GetIP returns the IPv4 address of the wg0 interface.
|
|
func GetIP() (string, error) {
|
|
iface, err := net.InterfaceByName("wg0")
|
|
if err != nil {
|
|
return "", fmt.Errorf("wg0 interface not found: %w", err)
|
|
}
|
|
addrs, err := iface.Addrs()
|
|
if err != nil {
|
|
return "", fmt.Errorf("failed to get wg0 addresses: %w", err)
|
|
}
|
|
for _, addr := range addrs {
|
|
if ipnet, ok := addr.(*net.IPNet); ok && ipnet.IP.To4() != nil {
|
|
return ipnet.IP.String(), nil
|
|
}
|
|
}
|
|
return "", fmt.Errorf("no IPv4 address on wg0")
|
|
}
|