Skip to content

Instantly share code, notes, and snippets.

@LuoZijun
Created September 7, 2019 03:55
Show Gist options
  • Save LuoZijun/6d34257a235d14f205fc17458c49c8a4 to your computer and use it in GitHub Desktop.
Save LuoZijun/6d34257a235d14f205fc17458c49c8a4 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"github.com/vishvananda/netlink"
)
// Note: Add route first.
// $ sudo ip route add 8.8.8.8 dev enp0s3
func main() {
// neigh_list, _ := netlink.NeighList(2, netlink.FAMILY_V4);
// for _, neigh := range neigh_list {
// s := fmt.Sprintf("%s %s", neigh.IP, neigh.HardwareAddr)
// fmt.Println(s)
// }
route_list, _ := netlink.RouteList(nil, netlink.FAMILY_V4);
for _, route := range route_list {
dst := "0.0.0.0/0";
if route.Dst != nil {
dst = route.Dst.String();
}
fmt.Println(route.String());
if dst == "8.8.8.8/32" {
// NOTE: delete route, but does not work.
fmt.Println(fmt.Sprintf("$ ip route del %s", dst));
netlink.RouteDel(&route);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment