#!/bin/bash
k3c_ip="192.168.2.1"
admin_password="c2hnZW50YWk\%3D"
#密码转义问题
function get_stok(){
stock=`curl "http://$k3c_ip/cgi-bin/" -H "Origin: http://$k3c_ip" -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh,zh-CN;q=0.9' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H "Referer: http://$k3c_ip/cgi-bin" -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'DNT: 1' --data-binary '{"method":"set","module":{"security":{"login":{"username":"admin","password":"c2hnZW50YWk%3D"}}},"_deviceType":"pc"}' --compressed ;`
echo $stock |jq '.module.security.login.stok' |sed 's/\"//g'
}
function get_sysinfo(){
curl "http://$k3c_ip/cgi-bin/stok=$1/data" -H "Origin: http://$k3c_ip" -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh,zh-CN;q=0.9' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H "Referer: http://$k3c_ip/cgi-bin" -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'DNT: 1' --data-binary '{"method":"get","module":{"device_manage":{"device_num":null},"network":{"wan_status":null},"device":{"info":null}},"_deviceType":"pc"}' --compressed
}
function get_onlineDevice(){
curl "http://$k3c_ip/cgi-bin/stok=$1/data" -H "Origin: http://$k3c_ip" -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh,zh-CN;q=0.9' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H "Referer: http://$k3c_ip/cgi-bin" -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'DNT: 1' --data-binary '{"method":"get","module":{"device_manage":{"client_list":null}},"_deviceType":"pc"}' --compressed
}
function get_sysStatus(){
curl "http://$k3c_ip/cgi-bin/stok=$1/data" -H "Origin: http://$k3c_ip" -H 'Accept-Encoding: gzip, deflate' -H 'Accept-Language: zh,zh-CN;q=0.9' -H 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.110 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H "Referer: http://$k3c_ip/cgi-bin" -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'DNT: 1' --data-binary '{"method":"get","module":{"device":{"info":null},"network":{"wan_status":null,"lan":null},"wireless":{"wifi_2g_status":null,"wifi_5g_status":null},"usb":{"device":null},"wisp":{"config":null}},"_deviceType":"pc"}' --compressed
}
stok=`get_stok`
json_sysinfo=`get_sysinfo $stok`
sys_uptime=`echo $json_sysinfo |jq '.module.device.info.uptime'` |sed 's/\"//g'
sys_cpu_used=`echo $json_sysinfo |jq '.module.device.info.cpu_used'` |sed 's/\"//g'
sys_cpu_freq=`echo $json_sysinfo |jq '.module.device.info.cpu_freq'` |sed 's/\"//g'
sys_wan_ip=`echo $json_sysinfo |jq '.module.device.info.wan_ip'` |sed 's/\"//g'
sys_total_ram=`echo $json_sysinfo |jq '.module.device.info.total_ram'` |sed 's/\"//g'
sys_model=`echo $json_sysinfo |jq '.module.device.info.model'` |sed 's/\"//g'
sys_current_time=`echo $json_sysinfo |jq '.module.device.info.current_time'` |sed 's/\"//g'
sys_used_ram=`echo $json_sysinfo |jq '.module.device.info.used_ram'` |sed 's/\"//g'
sys_upload_speed=`echo $json_sysinfo |jq '.module.network.wan_status.upload_speed'` |sed 's/\"//g'
sys_download_speed=`echo $json_sysinfo |jq '.module.network.wan_status.download_speed'` |sed 's/\"//g'
sys_internet_status=`echo $json_sysinfo |jq '.module.network.wan_status.internet_status'` |sed 's/\"//g'
sys_online_24G=`echo $json_sysinfo |jq '.module.device_manage.device_num.online_24G'` |sed 's/\"//g'
sys_online_5G=`echo $json_sysinfo |jq '.module.device_manage.device_num.online_5G'` |sed 's/\"//g'
sys_online_lan=`echo $json_sysinfo |jq '.module.device_manage.device_num.online_lan'` |sed 's/\"//g'
sys_online_guest=`echo $json_sysinfo |jq '.module.device_manage.device_num.online_guest'` |sed 's/\"//g'
json_onlineDevice=`get_onlineDevice $stok`
json_sysStatus=`get_sysStatus $stok`
sys_usb_name=`echo $json_sysinfo |jq '.module.usb.device.device_list.name'` |sed 's/\"//g'
sys_usb_free_capacity=`echo $json_sysinfo |jq '.module.usb.device.device_list.free_capacity'` |sed 's/\"//g'
sys_usb_total_capacity=`echo $json_sysinfo |jq '.module.usb.device.device_list.total_capacity'` |sed 's/\"//g'
echo $json_sysinfo |jq '.module'
echo $json_onlineDevice |jq '.module'
echo $json_sysStatus |jq '.module'