Home / 服务器 / 动态ip服务器获取ip后处理
用到了jq工具,安装:
sudo apt-get update
sudo apt-get install jq
#!/bin/bash
# 获取动态IP
dynamic_ip=$(curl -s https://myip.ipip.net/json | jq -r .data.ip)
# 如果成功获取到IP,则发起请求
if [ ! -z "$dynamic_ip" ]; then
echo "Dynamic IP: $dynamic_ip"
# 设置POST请求的参数,获取ip后自己处理
api_url="https://api.xxx.com/change_ip"
#post请求参数
para1="xxxx"
para2="xxxx"
# 发起POST请求
curl -X POST -d "ip=$dynamic_ip¶1=$para1¶2=$para2" $api_url
else
echo "Failed to get dynamic IP."
fi