48 lines
912 B
Go
48 lines
912 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net"
|
|
|
|
"github.com/crip/ripv2"
|
|
"github.com/crip/ripv2/routes"
|
|
)
|
|
|
|
func main() {
|
|
rip := ripv2.New()
|
|
routes := routes.New()
|
|
addr := net.UDPAddr{
|
|
Port: 520,
|
|
IP: net.ParseIP("224.0.0.9"),
|
|
}
|
|
iface := net.Interface{
|
|
Name: "enp1s0f1",
|
|
Flags: net.FlagMulticast,
|
|
}
|
|
conn, err := net.ListenMulticastUDP("udp4", &iface, &addr)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
defer conn.Close()
|
|
buff := make([]byte, 1024)
|
|
|
|
log.Println("waiting")
|
|
for {
|
|
n, UDPAddr, err := conn.ReadFromUDP(buff)
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
_ = UDPAddr
|
|
|
|
if err := rip.MParse(&buff, n); err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
routes.ParseRoutes(*UDPAddr, &rip.RIP)
|
|
for _, v := range routes {
|
|
fmt.Printf("Route:%s\tSubnet:%s\tNexthop:%s\tMetric:%d\tTime: %v\n", v.Addr.String(), v.Subnet.String(), v.Nexthop.String(), v.Metric, v.TTL.Unix())
|
|
}
|
|
fmt.Println("")
|
|
}
|
|
}
|