Guest User

Untitled

a guest
May 8th, 2020
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2. # Roku API tool
  3. # This tool sends requests to the roku streaming device API via ECP (external control protocol). It can effectively control any roku device on the local network. To find roku devices, just scan for port 8060 using nmap or ncat.
  4.  
  5. roku_host="" # IP or hostname of roku device
  6.  
  7. usage() {
  8. echo -e "usage: $0 <command>\nCommands:\n\tapplist - get list of installed apps\n\tactiveapp - shows app currently being used\n\tinfo - shows info about device\n\tlaunchapp <appid> - launch app specified by appID\n\tlockdown - keeps roku on the home screen"
  9. exit
  10. }
  11.  
  12. # Function sends a GET request to the roku on port 8060 (ECP) to request a resource.
  13. # GET requests usually request information from the roku, for example the app list.
  14. send_get() {
  15. resource=$1 # Format: example/resource
  16.  
  17. if test -z $resource; then
  18. echo "[!] error in 'send_get' function: resource var not set"
  19. exit
  20. fi
  21.  
  22. echo "[*] Sent request"
  23. request=`wget -O - -q http://$roku_host:8060/$resource`
  24. echo "[*] Response received"
  25. sleep 1
  26. echo $request
  27. }
  28.  
  29. # Function sends a POST request to roku on port 8060 (ECP) to request a resource.
  30. # POST requests to the API are typically for controlling the roku. Like pressing buttons.
  31. send_post() {
  32. resource=$1 # Format: example/resource
  33.  
  34. if test -z $resource; then
  35. echo "[!] error in 'send_post' function: resource var not set"
  36. exit
  37. fi
  38.  
  39. echo "[*] Sent request"
  40. request=`wget -O - -q --post-data="" http://$roku_host:8060/$resource`
  41. echo "[*] Command successful"
  42. sleep 1
  43. echo $request
  44. }
  45.  
  46. # Evalutate command line argument count
  47. if test $# == 0; then
  48. echo "error: at least one argument required"
  49. usage
  50. fi
  51.  
  52. # Make sure roku_host variable is set
  53. if test -z $roku_host; then
  54. echo "error: variable roku_host not set"
  55. exit 1
  56. fi
  57.  
  58. case $1 in
  59. "applist")
  60. send_get query/apps
  61. ;;
  62. "activeapp")
  63. send_get query/active-app
  64. ;;
  65. "info")
  66. send_get query/active-app
  67. ;;
  68. "launchapp")
  69. send_post launch/$2
  70. ;;
  71. "lockdown")
  72. while true
  73. do
  74. echo "[*] Keeping user on home screen"
  75. send_post keypress/Home
  76. sleep 3
  77. done
  78. ;;
  79. *)
  80. usage
  81. esac
RAW Paste Data