Windows下bat指令碼判斷連接埠是否可用

來源:互聯網
上載者:User

標籤:bat   telnet   


環境:

     一台伺服器上用了portmap做了連接埠轉寄,但是這個程式經常會跪,需要人工去重啟

解決思路:

通過bat來監控程式連接埠,不通時候自動重啟,如果連接埠可用,則會出來telnet進程,若連接埠不可用,則不會出現telnet進程。根據進程是否存在來判斷連接埠是否可用,因為telnet通的話,會直接跳轉視窗,無回顯,所以需要telnet時候啟用新視窗。

方法二

@echo offtitle PortMap存活監控!!!: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 %Date:~0,4%-%Date:~5,2%-%Date:~8,2% %Time:~0,2%:%Time:~3,2%ping -n 300 127.0.0.1 >nulgoto again

方法二

@echo offtitle PortMap存活監控!!!: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 -IM PortMap.exe & start "" "D:\PortMap1.6\PortMap.exe"):okecho 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 >nulgoto again


本文出自 “我本不是菜鳥” 部落格,請務必保留此出處http://ityunwei2017.blog.51cto.com/7662323/1924966

Windows下bat指令碼判斷連接埠是否可用

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.