This is my code :
@echo off
netstat -a -n | find /c "127.0.0.1:80"
pause
It return 1 Value in my CMD. i want to make IF Condition, for example, if The return value is 1 do this, if 0 do this. can you help me guys?
This is my code :
@echo off
netstat -a -n | find /c "127.0.0.1:80"
pause
It return 1 Value in my CMD. i want to make IF Condition, for example, if The return value is 1 do this, if 0 do this. can you help me guys?
Wrap the command in a for /f parsing the output.
@echo off
For /f %%A in ('netstat -a -n ^| find /c "127.0.0.1:80"') Do Set Count=%%A
If %Count% equ 0 (
echo Count = 0 do this
) Else (
echo Count not 0 do that
)
pause
You could probably just use this construct:
NetStat -na | Find "127.0.0.1:80" >Nul && (
Echo Found
) || (
Echo Not found
)
Change Echo Found
to the command(s) you need for one or more matches and Echo Not found
to the command(s) you need for no connection matches a little like this:
Depending upon your specific requirements you could possibly replace -na
with -np TCP
BTW your script is returning the value from find
not from netstat
.