babeld-cli.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/bash
  2. print_help () {
  3. echo "babeld-cli [interfaces|neighbors|routes|xroutes|version]"
  4. }
  5. dump=$(echo -e "dump\nquit" | netcat ::1 33123 -n)
  6. if [ ! "$1" ]; then
  7. print_help
  8. elif [ "$1" == "interfaces" ]; then
  9. echo -e "Interface\tState\tNext hop"
  10. echo "$dump" | grep "^add interface" | awk '{ split($0,a," "); print a[3], "\t", a[5], "\t", a[7] }'
  11. elif [ "$1" == "neighbors" ]; then
  12. echo -e "Neighbor ID\tIP address\tInterface\tReach\tRxcost\tTxcost\tCost"
  13. echo "$dump" | grep "^add neighbour" | awk '{ split($0,a," "); print a[3], "\t", a[5], "\t", a[7], "\t", a[9], "\t", a[13], "\t", a[15], "\t", a[17] }'
  14. elif [ "$1" == "routes" ]; then
  15. echo -e "Route ID\tPrefix\t\t\tInstalled\tID\t\t\tMetric\tRefmetrix\tNext hop\tInterface"
  16. echo "$dump" | grep "^add route" | awk '{ split($0,a," "); print a[3], "\t", a[5], "\t", a[9], "\t", a[11], "\t", a[13], "\t", a[15], "\t", a[17], "\t", a[19] }'
  17. elif [ "$1" == "xroutes" ]; then
  18. echo -e "Prefix\t\t\tMetric"
  19. echo "$dump" | grep "^add xroute" | awk '{ split($0,a," "); print a[5], "\t", a[9] }'
  20. elif [ "$1" == "version" ]; then
  21. version=$(echo "$dump" | grep "^version" | awk '{ split($0,a," "); print a[2] }')
  22. host=$(echo "$dump" | grep "^host" | awk '{ split($0,a," "); print a[2] }')
  23. id=$(echo "$dump" | grep "^my-id" | awk '{ split($0,a," "); print a[2] }')
  24. echo "Version: $version"
  25. echo "Host: $host"
  26. echo "Router ID: $id"
  27. else
  28. print_help
  29. fi