Windows under Bat script determines whether a port is available

Source: Internet
Author: User
Tags goto


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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.