本帖最后由 无时崩溃 于 2019-9-30 08:59 编辑
本脚本参考@liyafe1997 的脚本
原脚本https://mjjbbs.eu.org/forum.php?mod=viewthread&tid=557697
因ipcheck.need.sh挂掉了 原脚本无法继续使用 就改为利用其它网站api
并且在原基础上增加了微信推送功能 被墙ip加粗显示 以及 未被墙的静默推送(静默推送仅TG适用 Server酱api文档里没有这个功能)
改的比较差 大佬轻喷
使用方法如下:
在脚本同目录下创建名为 ip_list.csv 的文件
格式为 region,ip
例如 HK,12.34.56.78
效果图:
批注 2019-09-29 210931.png
(11.97 KB, 下载次数: 3)
(预计微信类似效果 没有具体测试 但是api文档支持Markdown
- #!/usr/bin/env bash
- #Telegram推送参数
- tg_bot_api="XXXXXX"
- tg_chat_id="XXX"
- #Server酱推送参数
- SCKEY="XXX"
- ip_list=/root/ip_list.csv
- tmp=/root/status.txt
- #系统检查
- check_sys(){
- if [ -f /etc/redhat-release ]; then
- release="centos"
- elif cat /etc/issue | grep -Eqi "debian"; then
- release="debian"
- elif cat /etc/issue | grep -Eqi "ubuntu"; then
- release="ubuntu"
- elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
- release="centos"
- elif cat /proc/version | grep -Eqi "debian"; then
- release="debian"
- elif cat /proc/version | grep -Eqi "ubuntu"; then
- release="ubuntu"
- elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
- release="centos"
- else
- release=""
- fi
- }
- #jq工具安装
- install_jq(){
- check_sys
- if [[ ${release} == "centos" ]]
- then
- check_jq=$(yum list installed jq|grep "jq"|wc -l)
- if [[ ${check_jq} -eq 0 ]]
- then
- yum install -y jq
- fi
- elif [[ ${release} == "ubuntu" || ${release} == "debian" ]]
- then
- check_jq=$(apt list installed jq|grep "jq"|wc -l)
- if [[ ${check_jq} -eq 0 ]]
- then
- apt install -y jq
- fi
- fi
- }
- #tcp连通性检测
- check_tcp(){
- install_jq
- time=$(date "+%Y-%m-%d-%H:%M:%S")
- alert_mode=0
- for (( i = 1; i <= $(cat ${ip_list}|wc -l); ++i )); do
- get_region=$(cat ${ip_list}|sed -n ''${i}'p'|awk -F ',' '{print$1}')
- get_ip=$(cat ${ip_list}|sed -n ''${i}'p'|awk -F ',' '{print$2}')
- tcp_status=$(curl -s --connect-timeout 5 --request GET --url 'https://api.50network.com/china-firewall/check/ip/tcp_ack/'${get_ip}'' |jq '.["firewall-enable"]')
- if [[ ${tcp_status} == "true" ]]; then
- echo "${get_region} | \`${get_ip}\` | TCP still ALIVE" >> ${tmp}
- elif [[ ${tcp_status} == "false" ]]; then
- echo "*${get_region} | ${get_ip} | TCP has been BLOCKED*" >> ${tmp}
- alert_mode=1
- else
- exit
- fi
- done
- msg_templete="***检测时间-${time}***
- \`主机状态\`
- $(cat ${tmp})"
- }
- #Telegram Bot推送
- teleGram_push(){
- text=$(echo "${msg_templete}"|python -c 'import sys;import urllib; print(urllib.quote_plus(sys.stdin.read()))')
- curl -s --connect-timeout 5 --retry 2 --request GET --url 'https://api.telegram.org/bot'${tg_bot_api}'/sendMessage?chat_id='${tg_chat_id}'&text='${text}'&parse_mode=markdown&disable_notification='${alert_mode}''
- rm -rf ${tmp}
- }
- #Server酱推送
- weChat_push(){
- text=$(echo "${msg_templete}"|python -c 'import sys;import urllib; print(urllib.quote_plus(sys.stdin.read()))')
- curl -s --connect-timeout 5 --retry 2 --request GET --url 'https://sc.ftqq.com/'${SCKEY}'.send?text='主人,你的小鸡检测结果出炉了!'&desp='${text}''
- rm -rf ${tmp}
- }
- check_tcp
- #两种推送不能并存 选其一
- teleGram_push
- #weChat_push
复制代码
不想复制粘贴的可以点这里下载 https://send.firefox.com/download/1e5fa9c5aa88aff2/#4TIMMJYUYaf-W6sVkzTxXQ
谢谢各位支持! |