#!/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