Last active 20 hours ago

send.sh Raw
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.
7FINGERPRINT="ZSbU9jU2AZWgnNagZ61vVua0RCZr46DT5eSwn8uHKsc8QFEFBhTVYPI7a1LWcrDAwOm%2F4AGv7rmTw%2F4xVTQqgA%3D%3D"
8RANDOM_STRING="SDQwjPd54R84tGaackbWmYNme4tmsD75"
9
10# Your User-Agent
11USER_AGENT="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36"
12
13REFERER_HEADER="https://hitools.hikvision.com/HiToolsDesigner/"
14ORIGIN_HEADER="https://hitools.hikvision.com"
15# Check if 'X-Requested-With: XMLHttpRequest' is also in your 'Copy as cURL'
16X_REQ_WITH_HEADER="XMLHttpRequest"
17
18
19# --- 2. Preparation ---
20
21# Create a secure temporary file to store cookies
22COOKIE_JAR=$(mktemp)
23
24# Ensure the cookie file is deleted on script exit
25trap "rm -f $COOKIE_JAR" EXIT
26
27# Your API URLs
28GET_SESSION_URL="https://hitools.hikvision.com/TSAPI/User?fingerprint=${FINGERPRINT}&r=${RANDOM_STRING}&platform=indepLink&area=Global"
29POST_PRODUCT_URL="https://hitools.hikvision.com/en/TSAPI/ESServe/v2/products"
30
31# Your JSON data
32JSON_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
49echo "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
54curl -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
63if [ ! -s "$COOKIE_JAR" ]; then
64 echo "Failed to get session! Cookie file is empty."
65 exit 1
66fi
67
68echo "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
75echo "POSTing data..."
76# -b: (cookie) Read cookies from the $COOKIE_JAR file
77curl -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
87echo
88echo "Script execution finished."