Environment:
A server on the use of Portmap do port forwarding, but this program often kneel, need to manually restart
Solution Ideas:
Through the bat to monitor the program port, does not automatically restart the time, if the port is available, then the Telnet process, if the port is not available, the Telnet process will not occur. Depending on whether the process exists to determine whether the port is available, because Telnet will jump directly to the window, no echo, so the need to Telnet time to enable the new window.
method two
@echo  OFFTITLE PORTMAP survival monitoring!!! :againset ip=127.0.0.1set port=8080start telnet.exe %ip% %port%ping -7 127.0.0.1 > nulltasklist|findstr /i "Telnet.exe" > nulif errorlevel 1 (Goto err) else (Goto ok):errtasklist|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"): oktaskkill /f -IM "Telnet.exe" >> nulecho portmap services is running %d Ate:~0,4%-%date:~5,2%-%date:~8,2% %time:~0,2%:%time:~3,2%ping -n 300 127.0.0.1 > Nulgoto again
Method Two
@echo Offtitle portmap survival monitoring!!! : Againset ip=127.0.0.1set port=8080netstat-ano|findstr%ip%:%port%|findstr-i establishedif ERRORLEVEL 1 (goto err) Else (goto OK): Errtasklist|findstr-i "Portmap.exe" if ERRORLEVEL 1 (start "" D:\PortMap1.6\PortMap.exe ") Else (taskkill/f-I M PortMap.exe & Start "" D:\PortMap1.6\PortMap.exe "): Okecho PortMap Services is running%date:~0,4%-%date:~5,2%-%d ate:~8,2%%time:~0,2%:%time:~3,2%ping-n 127.0.0.1 >nulgoto again
This article is from "I am not a rookie" blog, please be sure to keep this source http://ityunwei2017.blog.51cto.com/7662323/1924966
Windows under Bat script determines whether a port is available