Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- OLDIFS="${IFS}"
- TIMEOUT=10
- HOST="192.168.11.77"
- SRC=1
- FREQ=12000
- POL="V"
- SYS="DVBS"
- RATE=20000
- DEFAULT_PIDS="1,16,17,18,20,21,8191"
- if [ ! -z "${*}" ]; then
- while [ "${1:0:1}" == "-" ]; do
- case "${1}" in
- "-t"|"--timeout")
- TIMEOUT="${2}"
- shift 2;
- ;;
- "-h"|"--host")
- HOST="${2}"
- shift 2;
- ;;
- "-s"|"--src"|"--source")
- SRC="${2}"
- shift 2;
- ;;
- "-f"|"--freq"|"--frequency")
- FREQ="${2}"
- shift 2;
- ;;
- "-p"|"--pol"|"--polarity")
- POL="${2}"
- shift 2;
- ;;
- "-sys"|"--sys"|"--system")
- SYS="${2}"
- shift 2;
- ;;
- "-sr"|"--symbol-rate")
- RATE="${2}"
- shift 2;
- ;;
- *)
- echo "Help for ${0}:"
- echo ""
- echo "-t --timeout .. (int) Seconds to wait for data from a PID (Def: ${TIMEOUT})"
- echo "-s --src, --source .. (int) DiSEqC Source"
- echo "-f --freq, --frequency .. (int) Transponder Frequency"
- echo "-p --pol, --polarity .. [H,V,L,R] LNB Polarization"
- echo "-s --sys, --system .. [DVBS,DVBS2] DVB System Type"
- echo "-sr --symbol-rate .. (int) Transponder Symbol Rate"
- echo ""
- echo "By default, the tool will search for the following PIDS:"
- echo "${DEFAULT_PIDS}"
- echo "You can specify a set of PIDs like above, or a range"
- echo "such as 7400-7600. To scan a generated range of PIDs"
- echo "you can specify a PID with a + sign, eg +7500, and the tool"
- echo "will search for 7500-7530"
- exit 1;
- ;;
- esac
- done
- fi
- FOUNDPIDS=();
- URL="http://${HOST}:8080/?src=1${SRC}&freq=${FREQ}&pol=${POL}&msys=${SYS}&sr=${RATE}&pids="
- TESTFILE="/mnt/d/test.ts"
- scanpid() {
- if [ -f "${TESTFILE}" ]; then
- rm "${TESTFILE}"
- touch "${TESTFILE}"
- fi
- echo "Scanning PID(s) on ${FREQ}${POL} @ ${RATE}sym/s (waiting up to ${TIMEOUT} seconds): ${1}... "
- #curl --silent "${URL}${1}" --connect-timeout ${TIMEOUT} --max-time ${TIMEOUT} --max-filesize 1k -o "${TESTFILE}"
- wget -q --show-progress --tries=1 --timeout ${TIMEOUT} -O - "${URL}${1}" | dd of=${TESTFILE} iflag=fullblock bs=512 count=1 2>/dev/null
- RES=$?
- return ${RES}
- }
- runmain() {
- scanpid "${1}"
- local RES=$?
- if [ ${RES} -eq 0 ]; then
- local SIZE=$(stat --printf "%s" "${TESTFILE}");
- if [ ${SIZE} -gt 0 ]; then
- if [ $(echo "${1}" | grep -c "\,") -eq 0 ]; then
- FOUNDPIDS+=(${1})
- echo "Data detected on PID ${1}!"
- else
- local PIDA=($(echo "${1}" | tr ',' ' '));
- local PIDC=${#PIDA[@]};
- local PIDL=$(echo ${PIDC} | awk '{print int($1/2)}')
- local PID1=""
- local PID2=""
- for f in $(seq 0 $((PIDL - 1))); do
- PID1+="${PIDA[${f}]},"
- done
- for f in $(seq ${PIDL} $((PIDC - 1))); do
- PID2+="${PIDA[${f}]},"
- done
- echo ""
- runmain "${PID1::-1}"
- runmain "${PID2::-1}"
- # OLDIFS="${IFS}"
- # IFS=$'\n'
- # for f in $(echo "${PIDS}" | tr ',' '\n'); do
- # runmain "${f}";
- # done
- # IFS="${OLDIFS}"
- fi
- else
- echo ""
- fi
- else
- echo ""
- fi
- }
- if [ ! -z "${1}" ]; then
- if [ $(echo "${1}" | grep "\," -c) -gt 0 ]; then
- PIDS="${1}"
- else
- MINPID=${1}
- if [ "${MINPID:0:1}" == "+" ]; then
- PIDS=$(seq -s"," ${MINPID} $((MINPID+30)))
- elif [ $(echo "${MINPID}" | grep -c "\-") -gt 0 ]; then
- MAXPID=$(echo "${MINPID}" | cut -d'-' -f2)
- MINPID=$(echo "${MINPID}" | cut -d'-' -f1)
- RANGE="${MINPID} - ${MAXPID}"
- echo "Scanning range: ${RANGE}"
- MAX30PID=${MINPID}
- while [ ${MINPID} -le ${MAXPID} ]; do
- MAX30PID=$((MINPID + 30))
- if [ ${MAX30PID} -gt ${MAXPID} ]; then
- MAX30PID=${MAXPID}
- fi
- PIDS=$(seq -s"," ${MINPID} ${MAX30PID})
- MINPID=$((MAX30PID + 1))
- runmain "${PIDS}"
- done
- unset PIDS
- elif [ ${MINPID} -gt 0 ]; then
- PIDS="$(echo "${MINPID}" | sed "s|+||")"
- else
- echo "Usage: ${0} [pid|pids]"
- exit 1;
- fi
- fi
- else
- PIDS="${DEFAULT_PIDS}"
- fi
- if [ ! -z "${PIDS}" ]; then
- runmain "${PIDS}"
- fi
- if [ ${#FOUNDPIDS[@]} -gt 0 ]; then
- echo "Found PIDS: ${FOUNDPIDS[*]}"
- else
- if [ -z "${RANGE}" ]; then
- echo "Did not find any PIDs (Searched: ${PIDS})"
- else
- echo "Did not find any PIDs (Searched PID range: ${RANGE})"
- fi
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement