创建一个文件 autoRestart.bat
然后用记事本或者其他编辑器打开,输入如下内容,涉及到地址的地方自己修改,然后保存
@echo off
title 可爱猫iHttp存活监控
:again
set ip=0.0.0.0
set port=8090
netstat -ano|findstr %ip%:%port%|findstr -i LISTENING
if ERRORLEVEL 1 (goto err) else (goto ok)
:err
tasklist|findstr -i "可爱猫.exe"
if ERRORLEVEL 1 (start "" "D:\mysoft\可爱猫5.5.4\可爱猫.exe") else (taskkill /F -IM 可爱猫.exe & start "" "D:\mysoft\可爱猫5.5.4\可爱猫.exe")
:ok
echo 可爱猫iHttp Services is running %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%
ping -n 10 127.0.0.1 >nul
goto again
后面就是双击这个 bat 就好了,如果看到如下返回就是成功了
TCP 0.0.0.0:8090 0.0.0.0:0 LISTENING 2516
可爱猫iHttp Services is running 2023-03-05 23:26
如果没看到就自己改下脚本,我这里说原理,顺便教大家怎么改
先执行下面命令
C:\Users\Administrator>netstat -ano
活动连接
协议 本地地址 外部地址 状态 PID
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 972
TCP 0.0.0.0:443 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:888 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:1433 0.0.0.0:0 LISTENING 3052
TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 3736
TCP 0.0.0.0:5985 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:8090 0.0.0.0:0 LISTENING 8844
TCP 0.0.0.0:8680 0.0.0.0:0 LISTENING 8476
TCP 0.0.0.0:8888 0.0.0.0:0 LISTENING 5488
TCP 0.0.0.0:21632 0.0.0.0:0 LISTENING 6648
TCP 0.0.0.0:33890 0.0.0.0:0 LISTENING 708
TCP 0.0.0.0:47001 0.0.0.0:0 LISTENING 4
TCP 0.0.0.0:49664 0.0.0.0:0 LISTENING 544
TCP 0.0.0.0:49665 0.0.0.0:0 LISTENING 1268
TCP 0.0.0.0:49666 0.0.0.0:0 LISTENING 1752
TCP 0.0.0.0:49667 0.0.0.0:0 LISTENING 2196
TCP 0.0.0.0:49682 0.0.0.0:0 LISTENING 696
TCP 0.0.0.0:49691 0.0.0.0:0 LISTENING 5264
TCP 0.0.0.0:49702 0.0.0.0:0 LISTENING 684
TCP 122.114.52.57:80 157.90.182.28:34866 ESTABLISHED 4
TCP 122.114.52.57:139 0.0.0.0:0 LISTENING 4
TCP 122.114.52.57:8888 104.152.52.15:37155 ESTABLISHED 5488
TCP 122.114.52.57:33890 91.240.118.187:56237 SYN_RECEIVED 708
TCP 122.114.52.57:33890 152.89.196.36:19155 ESTABLISHED 708
TCP 122.114.52.57:33890 152.89.196.122:50784 ESTABLISHED 708
TCP 122.114.52.57:33890 223.70.251.63:62804 ESTABLISHED 708
TCP 122.114.52.57:50211 20.197.71.89:443 ESTABLISHED 3344
TCP 122.114.52.57:50721 117.89.177.107:443 ESTABLISHED 8476
TCP 122.114.52.57:51098 211.149.195.30:80 ESTABLISHED 8844
TCP 122.114.52.57:51111 23.206.250.58:80 ESTABLISHED 696
TCP 122.114.52.57:51126 42.187.182.106:443 TIME_WAIT 0
TCP 122.114.52.57:62181 124.71.79.99:80 CLOSE_WAIT 3100
TCP 127.0.0.1:10250 0.0.0.0:0 LISTENING 9000
TCP 127.0.0.1:11789 0.0.0.0:0 LISTENING 6648
TCP 127.0.0.1:11789 127.0.0.1:51099 ESTABLISHED 6648
TCP 127.0.0.1:12459 0.0.0.0:0 LISTENING 284
TCP 127.0.0.1:20592 0.0.0.0:0 LISTENING 6648
TCP 127.0.0.1:20592 127.0.0.1:51125 TIME_WAIT 0
TCP 127.0.0.1:51099 127.0.0.1:11789 ESTABLISHED 8476
TCP 127.0.0.1:51413 0.0.0.0:0 LISTENING 5384
TCP 192.168.162.223:139 0.0.0.0:0 LISTENING 4
TCP [::]:80 [::]:0 LISTENING 4
TCP [::]:135 [::]:0 LISTENING 972
TCP [::]:443 [::]:0 LISTENING 4
TCP [::]:445 [::]:0 LISTENING 4
TCP [::]:888 [::]:0 LISTENING 4
TCP [::]:1433 [::]:0 LISTENING 3052
TCP [::]:3306 [::]:0 LISTENING 3736
TCP [::]:5985 [::]:0 LISTENING 4
TCP [::]:33890 [::]:0 LISTENING 708
TCP [::]:47001 [::]:0 LISTENING 4
TCP [::]:49664 [::]:0 LISTENING 544
TCP [::]:49665 [::]:0 LISTENING 1268
TCP [::]:49666 [::]:0 LISTENING 1752
TCP [::]:49667 [::]:0 LISTENING 2196
TCP [::]:49682 [::]:0 LISTENING 696
TCP [::]:49691 [::]:0 LISTENING 5264
TCP [::]:49702 [::]:0 LISTENING 684
UDP 0.0.0.0:123 *:* 3212
UDP 0.0.0.0:5353 *:* 1824
UDP 0.0.0.0:5355 *:* 1824
UDP 0.0.0.0:33890 *:* 708
UDP 0.0.0.0:59904 *:* 2132
UDP 122.114.52.57:137 *:* 4
UDP 122.114.52.57:138 *:* 4
UDP 127.0.0.1:52041 *:* 3812
UDP 192.168.162.223:137 *:* 4
UDP 192.168.162.223:138 *:* 4
UDP [::]:123 *:* 3212
UDP [::]:5353 *:* 1824
UDP [::]:5355 *:* 1824
UDP [::]:33890 *:* 708
找到你 iHttp 的端口那个进程,比如上面中 找到的是
TCP 0.0.0.0:8090 0.0.0.0:0 LISTENING 8844
当然你有可能找到是下面这样
TCP 127.0.0.1:8090 104.152.52.15:37155 ESTABLISHED 5488
然后说下 命令的意思
set ip=0.0.0.0
set port=8090
# 上面我想大家都懂,主要下面,意思是找到的连接里面 进行 findstr "LISTENING" 如果存在就认为服务活着,同理就是死了
# 顺着这个思路,我想大家都可以写出自己的监控了。
netstat -ano|findstr %ip%:%port%|findstr -i LISTENING
还有这一句
# 这里的 10 代表10秒监控一次 你可以改为60 一分钟一次 600 10分钟一次 你开心就好
ping -n 10 127.0.0.1 >nul
隐藏内容有宝藏哦!想知道就回复一下吧!
最后于 2023-3-9
被admin编辑
,原因: