Need to check if the process is running and the port that is being used(8086 and 8085) is in listening state, using a batch file
Asked
Active
Viewed 8,156 times
3
-
2Possible duplicate of [Command line for looking at specific port](https://stackoverflow.com/questions/12010631/command-line-for-looking-at-specific-port) – Maurice Meyer Oct 30 '17 at 08:45
-
What part are you actually struggling with - and why a batch file? – BugFinder Oct 30 '17 at 08:46
-
send a message to that specific port and see if it can receive – Rahul Oct 30 '17 at 08:47
-
Needed a batch file as i'm using it in an alert system, so that i will be notified if port is not listening – Tanuja kurkute Oct 31 '17 at 12:29
2 Answers
5
netstat /o /a | find /i "listening" | find ":8086" >nul 2>nul && (
echo 8086 is open
) || (
echo 8086 is Not open
)

npocmaka
- 55,367
- 18
- 148
- 187
-
1Thanks i did with findstr netstat -o -n -a | findstr 8086 if %ERRORLEVEL% equ 0 goto FOUND echo port not found goto FIN :FOUND echo port found :FIN Note: When an item is not found FINDSTR will return an %ERRORLEVEL% > 0 if item is found FINDSTR will return an %ERRORLEVEL% = 0 – Tanuja kurkute Oct 31 '17 at 12:32
-
3Also as a one-liner which is useful sometimes netstat -nao | findstr "LISTENING" | findstr "0:8086" >nul 2>nul && (echo Port 8086 is open) || (echo Port 8086 is closed && exit 1) Note the "exit 1" which returns an %ERRORLEVEL% > 0 – posix99 Jun 27 '18 at 13:12
1
netstat -o -n -a | findstr 8086
if %ERRORLEVEL% equ 0 goto FOUND
echo port not found
goto FIN
:FOUND
echo port found
:FIN
Note: When an item is not found FINDSTR will return an %ERRORLEVEL% > 0 if item is found FINDSTR will return an %ERRORLEVEL% = 0

npocmaka
- 55,367
- 18
- 148
- 187

Tanuja kurkute
- 41
- 1
- 4