Old 12th January 2016, 22:57   #1
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Check if Port is open

Hi All,

I am trying to use this in my installer to see if a port is open. I need to show a message box if the port cannot be used or proceed if its ok to use the port.

http://nsis.sourceforge.net/Check_open_ports

I am not able to figure out the example in this page. If I used the condition with {If}, how would this be:

${If} ${TCPPortOpen} $PortNumber
MessageBox MB_OK|MB_ICONSTOP "$PortNumber is already using by another program..."
Abort
${Else}
MessageBox MB_OK"$PortNumber is open to use"

Is this correct?
pkonduru is offline   Reply With Quote
Old 12th January 2016, 23:27   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Looks OK to me. What happens when you run your installer?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 13th January 2016, 00:09   #3
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
The installation proceeds no matter what port I give. Is there any port on my Windows machine I can specify where this check will fail and abort?
pkonduru is offline   Reply With Quote
Old 13th January 2016, 03:46   #4
JasonFriday13
Major Dude
 
JasonFriday13's Avatar
 
Join Date: May 2005
Location: New Zealand
Posts: 916
There should be an ${EndIf} at the end of that code. Do you get any warnings when you compile the script?

"Only a MouseHelmet will save you from a MouseTrap" -Jason Ross (Me)
NSIS 3 POSIX Ninja
Wiki Profile
JasonFriday13 is offline   Reply With Quote
Old 13th January 2016, 18:09   #5
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Hi Jason,

Yes I do have a ${EndIf}, didnt post the whole snippet, here it is:


${If} ${TCPPortOpen} $PortNumber
MessageBox MB_OK|MB_ICONSTOP "$PortNumber is already using by another program..."
Abort
${Else}
MessageBox MB_OK "$PortNumber is open to use"
${EndIf}

what I don't get is , if the Port is open as per this line below,

${If} ${TCPPortOpen} $PortNumber

Doesn't this mean that the port is OK to use and proceed with the install?
pkonduru is offline   Reply With Quote
Old 13th January 2016, 21:11   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,442
Open probably means some application is using it. I don't understand how this can be so hard to test, since you are checking for ports I assume you have some application that opens a port so you can just run it and test your installer. You can also use netstat or download TCPView to find open ports on your machine...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 14th January 2016, 21:32   #7
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Thanks Anders. My understanding was "TCPPortOpen" meant an "Open" port which one could use, sorry for the confusion. I did verify that the code is working by entering a port which was in use by the application.

Thank you everyone for the inputs.
pkonduru is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump