Advertisement
Guest User

Untitled

a guest
Dec 27th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. TRANSUSER=your_transmission_username
  4. TRANSPASS=your_transmission_password
  5. TRANSHOST=192.168.x.xx
  6.  
  7. error( )
  8. {
  9. echo "$@" 1>&2
  10. exit 1
  11. }
  12.  
  13. error_and_usage( )
  14. {
  15. echo "$@" 1>&2
  16. usage_and_exit 1
  17. }
  18.  
  19. usage( )
  20. {
  21. echo "Usage: `dirname $0`/$PROGRAM"
  22. }
  23.  
  24. usage_and_exit( )
  25. {
  26. usage
  27. exit $1
  28. }
  29.  
  30. version( )
  31. {
  32. echo "$PROGRAM version $VERSION"
  33. }
  34.  
  35.  
  36. port_forward_assignment( )
  37. {
  38. echo 'Loading port forward assignment information...'
  39. if [ "$(uname)" == "Linux" ]; then
  40. client_id=`head -n 100 /dev/urandom | sha256sum | tr -d " -"`
  41. fi
  42. if [ "$(uname)" == "FreeBSD" ]; then
  43. client_id=`head -n 100 /dev/urandom | shasum -a 256 | tr -d " -"`
  44. fi
  45.  
  46. json=`curl "http://209.222.18.222:2000/?client_id=$client_id" 2>/dev/null`
  47. if [ "$json" == "" ]; then
  48. echo Port forwarding is already activated on this connection, has expired, or you are not connected to a PIA region that supports port forwarding
  49. exit 0
  50. fi
  51.  
  52. echo server returned $json
  53.  
  54. #trim VPN forwarded port from JSON
  55. PORT=$(echo $json | awk 'BEGIN{r=1;FS="[{}\":]+"} /port/{r=0; print $3} END{exit r}')
  56. echo if successful, trimmed port is:$PORT
  57.  
  58. #change transmission port on the fly
  59.  
  60. transmission-remote $TRANSHOST --auth $TRANSUSER:$TRANSPASS -p "$PORT"
  61. echo remember to run no longer than 2 mins after reconnecting/connecting to vpn server.
  62. }
  63.  
  64.  
  65.  
  66. EXITCODE=0
  67. PROGRAM=`basename $0`
  68. VERSION=2.1
  69.  
  70. while test $# -gt 0
  71. do
  72. case $1 in
  73. --usage | --help | -h )
  74. usage_and_exit 0
  75. ;;
  76. --version | -v )
  77. version
  78. exit 0
  79. ;;
  80. *)
  81. error_and_usage "Unrecognized option: $1"
  82. ;;
  83. esac
  84. shift
  85. done
  86.  
  87. port_forward_assignment
  88.  
  89. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement