Last active
March 18, 2017 15:31
-
-
Save dsturnbull/4974638 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can use cURL to upload packet captures to Packetloop. We created a simple script that shows how to login, list capture points, create capture points, upload and also check processing status. | |
## variables | |
PL_ENDPOINT=https://www.packetloop.com | |
PL_USERNAME=... # your packetloop email address | |
PL_PASSWORD=... # your packetloop password | |
## logging in | |
PL_TOKEN=$(curl -3 -s -b cookies.jar -c cookies.jar -X GET "$PL_ENDPOINT/init") | |
curl -3 -s -H "X-CSRF-Token: $PL_TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -b cookies.jar -c cookies.jar -X POST "$PL_ENDPOINT/users/sign_in.json?pretty=true" -d "{ \"user\": { \"email\": \"$PL_USERNAME\", \"password\": \"$PL_PASSWORD\" } }" | |
## list capture points | |
curl -3 -s -H "Accept: application/json" -b cookies.jar -c cookies.jar -X GET "$PL_ENDPOINT/devices.json?pretty=true" | |
## creating capture points | |
PL_DEVICE_NAME=my_capture_point_name | |
curl -3 -s -H "X-CSRF-Token: $PL_TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -b cookies.jar -c cookies.jar -X POST "$PL_ENDPOINT/devices.json?pretty=true" -d "{ \"device\": { \"name\": \"$PL_DEVICE_NAME\" } }" | |
## upload file(s) | |
IDS=() | |
# set PL_DEVICE_ID from one of the capture points (devices) created or listed from the steps above | |
PL_DEVICE_ID=... | |
# repeat these two steps for any files you want to upload | |
PL_UPLOAD_FILE=~/Downloads/blah.pcap | |
IDS+=($(curl -3 -s -H "X-CSRF-Token: $PL_TOKEN" -H "Accept: application/json" -b cookies.jar -c cookies.jar -X POST "$PL_ENDPOINT/settings/captures.json?device_id=$PL_DEVICE_ID" -F "file=@$UPLOAD_FILE" | sed -e 's/.*://' -e 's/}//')) | |
# submit uploads | |
IDS_ARRAY=$(printf ",%s" "${IDS[@]}") | |
IDS_ARRAY=${IDS_ARRAY:1} | |
IDS_ARRAY="[$IDS_ARRAY]" | |
curl -3 -s -H "X-CSRF-Token: $PL_TOKEN" -H "Content-Type: application/json" -H "Accept: application/json" -b cookies.jar -c cookies.jar -X PUT "$PL_ENDPOINT/settings/captures/submit.json" -d "{ \"ids\": $IDS_ARRAY, \"device_id\": \"$PL_DEVICE_ID\" }" | |
## get status | |
curl -3 -s -H "X-CSRF-Token: $PL_TOKEN" -H "Accept: application/json" -b cookies.jar -c cookies.jar -X GET "$PL_ENDPOINT/upload/status.json?pretty=true" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment