DirecTV – API JSON Service

If you have your DirecTV Unit plugged into your network at home you could run a couple fun commands.

#!/bin/sh

#  DirecTV.sh
#
#
#  Created by David Kittell on 1/3/18.
#

# Variables - Start
unitIP="<IP ADDRESS>"
# Variables - Stop

# Get Unit Serial Number
json=$(curl -s -X GET http://${unitIP}:8080/info/getSerialNum)
#echo ${json}
serialNum=$(echo ${json} | jq ".serialNum" | sed 's/"//g')
echo "Unit Serial Number: ${serialNum}"

# Get IDs and Version
json=$(curl -s -X GET http://${unitIP}:8080/info/getVersion)
#echo ${json}
accessCardId=$(echo ${json} | jq ".accessCardId" | sed 's/"//g')
receiverId=$(echo ${json} | jq ".receiverId" | sed 's/"//g')
version=$(echo ${json} | jq ".version" | sed 's/"//g')
systemTime=$(echo ${json} | jq ".systemTime" | sed 's/"//g')

unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
  systemTimeHR=$(date -d @${systemTime} '+%Y-%m-%d %I:%M:%S %p')
elif [[ "$unamestr" == 'FreeBSD' ]]; then
  systemTimeHR=$(date -r ${systemTime} '+%Y-%m-%d %I:%M:%S %p')
elif [[ "$unamestr" == 'Darwin' ]]; then
  systemTimeHR=$(date -r ${systemTime} '+%Y-%m-%d %I:%M:%S %p')
fi

echo "Unit Version: ${version}"
echo "Unit IDs:\n     Access Card ID: ${accessCardId}\n     Reciever ID: ${receiverId}"

echo "Unit DateTime: ${systemTimeHR}"
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.