modified: cmd/pmomusic/main.go new file: internal/netutils/ip_detect.go new file: internal/netutils/list_all_ip.go modified: internal/soap/soap.go modified: internal/ssdp/responder.go modified: internal/ssdp/ssdp.go modified: internal/upnp/http.go new file: internal/upnp/server.go new file: internal/upnp/xml/AVTransport.xml new file: internal/upnp/xml/ConnectionManager.xml new file: internal/upnp/xml/RenderingControl.xml
50 lines
842 B
Go
50 lines
842 B
Go
package netutils
|
|
|
|
import (
|
|
"net"
|
|
)
|
|
|
|
// ListAllIPs returns a map of interface names to their associated IPv4 addresses.
|
|
func ListAllIPs() map[string][]string {
|
|
result := make(map[string][]string)
|
|
|
|
ifaces, err := net.Interfaces()
|
|
if err != nil {
|
|
result["error"] = []string{err.Error()}
|
|
return result
|
|
}
|
|
|
|
for _, iface := range ifaces {
|
|
if iface.Flags&net.FlagUp == 0 {
|
|
continue // Ignore down interfaces
|
|
}
|
|
|
|
addrs, err := iface.Addrs()
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
var ips []string
|
|
for _, addr := range addrs {
|
|
var ip net.IP
|
|
switch v := addr.(type) {
|
|
case *net.IPNet:
|
|
ip = v.IP
|
|
case *net.IPAddr:
|
|
ip = v.IP
|
|
}
|
|
|
|
if ip == nil || ip.To4() == nil || ip.IsLoopback() {
|
|
continue
|
|
}
|
|
ips = append(ips, ip.String())
|
|
}
|
|
|
|
if len(ips) > 0 {
|
|
result[iface.Name] = ips
|
|
}
|
|
}
|
|
|
|
return result
|
|
}
|