Archive: Port scan


Port scan
Hi all, as I am installing an app that needs connection through TCP port I need to check whether the TCP port is already used. Is there a way to check whether the port number is used or not. Lets say I want to test whether the port 8443 is used by any other application, how would I do that through NSIS installer during installation.


You'd probably need to launch a third-party tcp ping or tcptrace mate, using Exec, ExecWait, or nsExec::Exec (look those up in the docs for details). Far as I know there's no plugin written to do that stuff, feel free to write one yourself :)


It's easy to get all used ports list, for example 'netstat -a' using nsExec or attached plug-in (re-worked not long ago :) ), but '|grep 8443' not works on most of Wins, so you will need to learn NSIS string and file functions to extract 8443 LISTENING string.


Ok how will I get the output of netstat -a command

I have tried the following:

ExecWait "netstat -a" $0

This did not work


Originally posted by bgosalci
Ok how will I get the output of netstat -a command

I have tried the following:

ExecWait "netstat -a" $0

This did not work
Hi,

I would recommand the nsExec plug-in like so:

nsExec::ExecToStack '"netstat" -a'
Pop $0

from the nsExec documentation: "...ExecToStack will push up to ${NSIS_MAX_STRLEN} characters of output onto the stack after the return value."

Hope this helps,

KenA

Thanks for reply but the value returned is = 0.

if used with timeout the returned value is = error.


Originally posted by bgosalci
Thanks for reply but the value returned is = 0.

if used with timeout the returned value is = error.
My bad, here's what should work.

nsExec::ExecToStack /TIMEOUT=5000 '"netstat.exe" -a'
Pop $0 ; retrieve the error code
StrCmp $0 "0" 0 not_ok
Pop $0 ; retrieve the output.
not_ok: ;error dealing code...
...

Should be better.:D

KenA

config.h(11):#define NSIS_MAX_STRLEN 1024
but I see few screens of data on netstat, exec 2log looks better for me.


I have found a utility that runs in Windows command line, which will do the work. If any one else needs this sort of utility than check the links.

Download:
http://www.microsoft.com/downloads/d...displaylang=en

Info:
http://support.microsoft.com/default...b;en-us;832919