Linux基础知识之获取请求ID内容(你知道哪些获取linux基本信息的常用命令)
一般环境都是通过请求ID也就是requestid去获取请求内容的。
一般获取requestid的方法是打开浏览器,请求网址后按F12,然后点击Network网络,选择All,接着看Response应答信息里面一般有RequestID的字段。
Requestid类型可能是:
①:uuid类型
可以使用uuid -d 命令提取时间戳和内容。
或者journalctl -xe | grep uuid
或者使用uuidparse命令去解析。
②:Base64编码类型
比如一串字符==这种
大小写和等号混合的字符,使用base64 --decode去解码。
echo "密文" | base64 --decode
举例:
echo -n "NjgyZTG1NM=" | base64 -d
③:requestid是URL编码
如果requestid中包含%20、%3A这种字符,可以使用curl或者Python去解码。
echo "密文" | python3 -c "import sys,urllibparse; print (urllib.parse.unquote(sys.stdin.read()))"
④:requestid是JWT编码(Json Web Token)
如果requestid类似eyJHc9.xxx,可能是JWT,可以使用jq解析。
echo "密文" |cut -d '.' -f 1 | base64 --decode| jq
JWT的payload部分可能是Base64URL编码。
⑤:requestid是16进制或者二进制编码
如果requestid是0xdeadbeef或者\x12\x34这种编码,可以使用xxd或者hexdump去解析:
echo "密文" | xxd -r -p
比如:
echo "0x616263" | xxd -r -p
⑥:requestid是时间戳。
date -d @时间戳 获取内容。
举例:
date -d @174789277
获取requestid的shell脚本:
vim requestid-decode.sh:
#! /bin/bash
if [ $# -ne 1]; then
echo "Usage:"
echo
echo "${0} request_id"
echo
exit 1
fi
#Base64 decode
decode_string=$(echo $1 |base64 -d)
if [ $? -ne 0 ]; then
echo "Invalid Request ID: ${1}"
exit 1
fi
#Split result
let t=16#$(echo ${decode_string} |awk -F '_' '{printf("%s",$1)}')
let ip=16#$(echo ${decode_string} |awk -F '_' '{printf("%s",$2)}')
let pid=16#$(echo ${decode_string} |awk -F '_' '{printf("%s",$3)}')
let cookie=16#$(echo ${decode_string} |awk -F '_' '{printf("%s",$4)}')
if [ ${cookie} -eq 0 ]; then
echo "Invalid Request ID"
exit
fi
# Get IP String
ip_string=""
while [ ${ip} -ne 0 ]; do
ip_string=${ip_string} `expr ${ip} % 256`
ip=`expr ${ip} / 256`
if [ ${ip} -ne 0 ]; then
ip_string=${ip_string}.
fi
done
# Get time string
time_string=$(date '+%Y-%m-%d %H:%M:%S' -d @$t)
#Output
echo "Time :" ${time_string}
echo "IP :" ${ip_string}
echo "PID :" ${pid}
echo "cookie :" ${cookie}
执行方式: sh requestid-decode.sh $request_id
鼓励的话语:不在巅峰时慕名而来,也不在低谷时刻离你而去,才够朋友!