limit-speed.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/bin/bash
  2. red='\e[1;31m'
  3. green='\e[0;32m'
  4. NC='\e[0m'
  5. MYIP=$(wget -qO- icanhazip.com);
  6. echo "Checking VPS"
  7. clear
  8. Green_font_prefix="\033[32m" && Red_font_prefix="\033[31m" && Green_background_prefix="\033[42;37m" && Red_background_prefix="\033[41;37m" && Font_color_suffix="\033[0m"
  9. Info="${Green_font_prefix}[ON]${Font_color_suffix}"
  10. Error="${Red_font_prefix}[OFF]${Font_color_suffix}"
  11. cek=$(cat /home/limit)
  12. NIC=$(ip -o $ANU -4 route show to default | awk '{print $5}');
  13. function start () {
  14. echo -e "Limit Speed All Service"
  15. read -p "Set maximum download rate (in Kbps): " down
  16. read -p "Set maximum upload rate (in Kbps): " up
  17. if [[ -z "$down" ]] && [[ -z "$up" ]]; then
  18. echo > /dev/null 2>&1
  19. else
  20. echo "Start Configuration"
  21. sleep 0.5
  22. wondershaper -a $NIC -d $down -u $up > /dev/null 2>&1
  23. systemctl enable --now wondershaper.service
  24. echo "start" > /home/limit
  25. echo "Done"
  26. fi
  27. }
  28. function stop () {
  29. wondershaper -ca $NIC
  30. systemctl stop wondershaper.service
  31. echo "Stop Configuration"
  32. sleep 0.5
  33. echo > /home/limit
  34. echo "Done"
  35. }
  36. if [[ "$cek" = "start" ]]; then
  37. sts="${Info}"
  38. else
  39. sts="${Error}"
  40. fi
  41. clear
  42. echo -e " =============================="
  43. echo -e " Limit Bandwidth Speed "
  44. echo -e " =============================="
  45. echo -e " Status $sts"
  46. echo -e " 1. Start Limit"
  47. echo -e " 2. Stop Limit"
  48. echo -e " Press CTRL+C to return"
  49. read -rp " Please Enter The Correct Number : " -e num
  50. if [[ "$num" = "1" ]]; then
  51. start
  52. elif [[ "$num" = "2" ]]; then
  53. stop
  54. else
  55. clear
  56. echo " You Entered The Wrong Number"
  57. menu
  58. fi