limit-speed.sh 1.4 KB

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