摘要:本文主要向大家介绍了Windows运维之Windows下bat脚本判断端口是否可用,通过具体的内容向大家展现,希望对大家学习Windows运维有所帮助。
本文主要向大家介绍了Windows运维之Windows下bat脚本判断端口是否可用,通过具体的内容向大家展现,希望对大家学习Windows运维有所帮助。
环境: 一台服务器上用了portmap做了端口转发,但是这个程序经常会跪,需要人工去重启解决思路:通过bat来监控程序端口,不通时候自动重启,如果端口可用,则会出来telnet进程,若端口不可用,则不会出现telnet进程。根据进程是否存在来判断端口是否可用,因为telnet通的话,会直接跳转窗口,无回显,所以需要telnet时候启用新窗口。方法二@echo off
title PortMap存活监控!!!
:again
set ip=127.0.0.1
set port=8080
start telnet.exe %ip% %port%
ping -7 127.0.0.1 > null
tasklist|findstr /i "telnet.exe" > nul
if ERRORLEVEL 1 (goto err) else (goto ok)
:err
tasklist|findstr -i "portmap.exe"
if ERRORLEVEL 1 (start "" "D:\PortMap1.6\PortMap.exe") else (taskkill /F -IM PortMap.exe & start "" "D:\PortMap1.6\PortMap.exe")
:ok
taskkill /F -IM "telnet.exe" >> nul
echo PortMap Services is running %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%
ping -n 300 127.0.0.1 >nul
goto again方法二@echo off
title PortMap存活监控!!!
:again
set ip=127.0.0.1
set port=8080
netstat -ano|findstr %ip%:%port%|findstr -i ESTABLISHED
if ERRORLEVEL 1 (goto err) else (goto ok)
:err
tasklist|findstr -i "portmap.exe"
if ERRORLEVEL 1 (start "" "D:\PortMap1.6\PortMap.exe") else (taskkill /F -IM PortMap.exe & start "" "D:\PortMap1.6\PortMap.exe")
:ok
echo PortMap Services is running %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%
ping -n 300 127.0.0.1 >nul
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注系统运维windows频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号