AnonymousNamefag

atget

Dec 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.76 KB | None | 0 0
  1. #!/usr/bin/env bash
  2. # Anti-Throttling GET
  3. # This script has a problem where the filename
  4. # has to be listed before any options or the
  5. # program chokes.  I'm too lazy to fix it. :P
  6.  
  7. file="$1"
  8. shift
  9. declare -i timeout=5
  10. declare -i randbase=500
  11.  
  12. while getopts ":T:R:" opt
  13. do
  14.     case $opt in
  15.       T) let timeout=$OPTARG;;
  16.       R) let randbase=$OPTARG;;
  17.       \?) echo "Invalid option: -$OPTARG" >&2;;
  18.     esac
  19. done
  20.  
  21. while true
  22. do
  23.     wget -c -T $timeout "$file"
  24.     declare -i p=$randbase*100  # 1/100 seconds base
  25.     declare -i q=$RANDOM%$p+1   # 1/100 seconds delay
  26.     declare -i r=$q*10000       # microseconds delay
  27.     declare -i s=$q%100         # fractional part
  28.     declare -i t=$q/100         # integer part
  29.     echo "Waiting $t.$s seconds..."
  30.     usleep $r
  31.     unset p q r s t
  32. done
Add Comment
Please, Sign In to add comment