v-list-sys-interfaces 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/bin/bash
  2. # info: list system interfaces
  3. # options: [format]
  4. #
  5. # The function for obtaining the list of network interfaces.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. format=${1-shell}
  11. # Includes
  12. source $VESTA/func/main.sh
  13. # Json function
  14. json_list_iface() {
  15. dev=$(cat /proc/net/dev |grep : |cut -f 1 -d : |tr -d ' ' |grep -v lo)
  16. int_counter=$(echo "$dev" | wc -l)
  17. i=1
  18. echo '['
  19. for interface in $dev; do
  20. if [ "$i" -lt "$int_counter" ]; then
  21. echo -e "\t\"$interface\","
  22. else
  23. echo -e "\t\"$interface\""
  24. fi
  25. (( ++i))
  26. done
  27. echo "]"
  28. }
  29. # Shell function
  30. shell_list_iface() {
  31. dev=$(cat /proc/net/dev |grep : |cut -f 1 -d : |tr -d ' ' |grep -v lo)
  32. if [ -z "$nohead" ]; then
  33. echo "INTERFACES"
  34. echo "----------"
  35. fi
  36. for interface in $dev; do
  37. echo "$interface"
  38. done
  39. }
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. # Listing domains
  44. case $format in
  45. json) json_list_iface ;;
  46. plain) nohead=1; shell_list_iface ;;
  47. shell) shell_list_iface ;;
  48. *) check_args '1' '0' '[format]' ;;
  49. esac
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. exit