and_cesbo

Script to get JSON data from stream analyzer

Aug 8th, 2019
407
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.68 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # Usage:
  4. # Save script to /usr/local/bin/astra-scan
  5. # Launch: astra-scan udp://239.255.1.1:1234
  6.  
  7. SERVER="example.com:8000"
  8. LOGIN="admin"
  9. PASS="admin"
  10. ADDR="$1"
  11.  
  12. URL="http://$LOGIN:$PASS@$SERVER/control/"
  13.  
  14. function getID() {
  15.     python -c "import json,sys; print(json.load(sys.stdin)[\"id\"])"
  16. }
  17.  
  18. function apiCall() {
  19.     CMD=$1
  20.     OPT=$2
  21.  
  22.     case $CMD in
  23.         "start")
  24.             curl -sX POST -d "{\"cmd\":\"scan-init\",\"scan\":\"$OPT\"}" $URL | getID
  25.             ;;
  26.         "check")
  27.             curl -sX POST -d "{\"cmd\":\"scan-check\",\"id\":\"$OPT\"}" $URL
  28.             ;;
  29.     esac
  30. }
  31.  
  32. ID=$(apiCall "start" "$ADDR")
  33. sleep 3
  34. apiCall "check" "$ID"
Add Comment
Please, Sign In to add comment