and_cesbo icon

Script to get JSON data from stream analyzer

and_cesbo | PRO | 08/08/19 07:43:57 AM UTC | 0 ⭐ | 476 👁️ | Never ⏰ | []
Bash |

680 B

|

None

|

0 👍

/

0 👎

#!/bin/sh
 
# Usage:
# Save script to /usr/local/bin/astra-scan
# Launch: astra-scan udp://239.255.1.1:1234
 
SERVER="example.com:8000"
LOGIN="admin"
PASS="admin"
ADDR="$1"
 
URL="http://$LOGIN:$PASS@$SERVER/control/"
 
function getID() {
    python -c "import json,sys; print(json.load(sys.stdin)[\"id\"])"
}
 
function apiCall() {
    CMD=$1
    OPT=$2
 
    case $CMD in
        "start")
            curl -sX POST -d "{\"cmd\":\"scan-init\",\"scan\":\"$OPT\"}" $URL | getID
            ;;
        "check")
            curl -sX POST -d "{\"cmd\":\"scan-check\",\"id\":\"$OPT\"}" $URL
            ;;
    esac
}
 
ID=$(apiCall "start" "$ADDR")
sleep 3
apiCall "check" "$ID"

Comments