send.sh
· 2.5 KiB · Bash
Raw
#!/bin/bash
# --- 1. Configuration (Critical!) ---
# These values are observed from your browser. They will likely expire!
# When the script fails, you may need to re-capture these two values from your browser.
FINGERPRINT="ZSbU9jU2AZWgnNagZ61vVua0RCZr46DT5eSwn8uHKsc8QFEFBhTVYPI7a1LWcrDAwOm%2F4AGv7rmTw%2F4xVTQqgA%3D%3D"
RANDOM_STRING="SDQwjPd54R84tGaackbWmYNme4tmsD75"
# Your User-Agent
USER_AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
REFERER_HEADER="https://hitools.hikvision.com/HiToolsDesigner/"
ORIGIN_HEADER="https://hitools.hikvision.com"
# Check if 'X-Requested-With: XMLHttpRequest' is also in your 'Copy as cURL'
X_REQ_WITH_HEADER="XMLHttpRequest"
# --- 2. Preparation ---
# Create a secure temporary file to store cookies
COOKIE_JAR=$(mktemp)
# Ensure the cookie file is deleted on script exit
trap "rm -f $COOKIE_JAR" EXIT
# Your API URLs
GET_SESSION_URL="https://hitools.hikvision.com/TSAPI/User?fingerprint=${FINGERPRINT}&r=${RANDOM_STRING}&platform=indepLink&area=Global"
POST_PRODUCT_URL="https://hitools.hikvision.com/en/TSAPI/ESServe/v2/products"
# Your JSON data
JSON_PAYLOAD='{
"bool": {
"or": {
"term": [
{
"key": "productBaseInfo.productSapId.keyword",
"value": "311326558"
}
]
}
},
"productBracket": true
}'
# --- 3. Step 1: Get Session ---
echo "Getting session..."
# -s: Silent mode
# -L: Follow redirects
# -c: (cookie jar) Write cookies to the $COOKIE_JAR file
# We also need to add UA and Referer to this GET request to simulate a browser
curl -s -L \
-A "$USER_AGENT" \
-H "Referer: $REFERER_HEADER" \
-H "Origin: $ORIGIN_HEADER" \
-H "X-Requested-With: $X_REQ_WITH_HEADER" \
-c "$COOKIE_JAR" \
"$GET_SESSION_URL"
# Check if the cookie file is empty
if [ ! -s "$COOKIE_JAR" ]; then
echo "Failed to get session! Cookie file is empty."
exit 1
fi
echo "Session and Cookies saved to: $COOKIE_JAR"
# You can inspect the cookies by uncommenting the next line
# cat $COOKIE_JAR
# --- 4. Step 2: POST Data Using the Session ---
echo "POSTing data..."
# -b: (cookie) Read cookies from the $COOKIE_JAR file
curl -X POST \
-b "$COOKIE_JAR" \
-A "$USER_AGENT" \
-H "Content-Type: application/json" \
-H "Referer: $REFERER_HEADER" \
-H "Origin: $ORIGIN_HEADER" \
-H "X-Requested-With: $X_REQ_WITH_HEADER" \
-d "$JSON_PAYLOAD" \
"$POST_PRODUCT_URL"
echo
echo "Script execution finished."
| 1 | #!/bin/bash |
| 2 | |
| 3 | # --- 1. Configuration (Critical!) --- |
| 4 | |
| 5 | # These values are observed from your browser. They will likely expire! |
| 6 | # When the script fails, you may need to re-capture these two values from your browser. |
| 7 | FINGERPRINT="ZSbU9jU2AZWgnNagZ61vVua0RCZr46DT5eSwn8uHKsc8QFEFBhTVYPI7a1LWcrDAwOm%2F4AGv7rmTw%2F4xVTQqgA%3D%3D" |
| 8 | RANDOM_STRING="SDQwjPd54R84tGaackbWmYNme4tmsD75" |
| 9 | |
| 10 | # Your User-Agent |
| 11 | USER_AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36" |
| 12 | |
| 13 | REFERER_HEADER="https://hitools.hikvision.com/HiToolsDesigner/" |
| 14 | ORIGIN_HEADER="https://hitools.hikvision.com" |
| 15 | # Check if 'X-Requested-With: XMLHttpRequest' is also in your 'Copy as cURL' |
| 16 | X_REQ_WITH_HEADER="XMLHttpRequest" |
| 17 | |
| 18 | |
| 19 | # --- 2. Preparation --- |
| 20 | |
| 21 | # Create a secure temporary file to store cookies |
| 22 | COOKIE_JAR=$(mktemp) |
| 23 | |
| 24 | # Ensure the cookie file is deleted on script exit |
| 25 | trap "rm -f $COOKIE_JAR" EXIT |
| 26 | |
| 27 | # Your API URLs |
| 28 | GET_SESSION_URL="https://hitools.hikvision.com/TSAPI/User?fingerprint=${FINGERPRINT}&r=${RANDOM_STRING}&platform=indepLink&area=Global" |
| 29 | POST_PRODUCT_URL="https://hitools.hikvision.com/en/TSAPI/ESServe/v2/products" |
| 30 | |
| 31 | # Your JSON data |
| 32 | JSON_PAYLOAD='{ |
| 33 | "bool": { |
| 34 | "or": { |
| 35 | "term": [ |
| 36 | { |
| 37 | "key": "productBaseInfo.productSapId.keyword", |
| 38 | "value": "311326558" |
| 39 | } |
| 40 | ] |
| 41 | } |
| 42 | }, |
| 43 | "productBracket": true |
| 44 | }' |
| 45 | |
| 46 | |
| 47 | # --- 3. Step 1: Get Session --- |
| 48 | |
| 49 | echo "Getting session..." |
| 50 | # -s: Silent mode |
| 51 | # -L: Follow redirects |
| 52 | # -c: (cookie jar) Write cookies to the $COOKIE_JAR file |
| 53 | # We also need to add UA and Referer to this GET request to simulate a browser |
| 54 | curl -s -L \ |
| 55 | -A "$USER_AGENT" \ |
| 56 | -H "Referer: $REFERER_HEADER" \ |
| 57 | -H "Origin: $ORIGIN_HEADER" \ |
| 58 | -H "X-Requested-With: $X_REQ_WITH_HEADER" \ |
| 59 | -c "$COOKIE_JAR" \ |
| 60 | "$GET_SESSION_URL" |
| 61 | |
| 62 | # Check if the cookie file is empty |
| 63 | if [ ! -s "$COOKIE_JAR" ]; then |
| 64 | echo "Failed to get session! Cookie file is empty." |
| 65 | exit 1 |
| 66 | fi |
| 67 | |
| 68 | echo "Session and Cookies saved to: $COOKIE_JAR" |
| 69 | # You can inspect the cookies by uncommenting the next line |
| 70 | # cat $COOKIE_JAR |
| 71 | |
| 72 | |
| 73 | # --- 4. Step 2: POST Data Using the Session --- |
| 74 | |
| 75 | echo "POSTing data..." |
| 76 | # -b: (cookie) Read cookies from the $COOKIE_JAR file |
| 77 | curl -X POST \ |
| 78 | -b "$COOKIE_JAR" \ |
| 79 | -A "$USER_AGENT" \ |
| 80 | -H "Content-Type: application/json" \ |
| 81 | -H "Referer: $REFERER_HEADER" \ |
| 82 | -H "Origin: $ORIGIN_HEADER" \ |
| 83 | -H "X-Requested-With: $X_REQ_WITH_HEADER" \ |
| 84 | -d "$JSON_PAYLOAD" \ |
| 85 | "$POST_PRODUCT_URL" |
| 86 | |
| 87 | echo |
| 88 | echo "Script execution finished." |