limit-speed.sh 1.5 KB

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