Menu Close

Poke! that port…

We are always using telnet to test TCP port availability, and it is almost always available. In the event that it is not, or you want something a little more robust, I have been playing around with a script that I found on serverfault here:
http://serverfault.com/questions/560081/check-port-open-without-telnet

poke.ps1 is a cmdlet written in powershell to tell you whether or not a TCP port is open on a particular host.

Download:

poke.ps1

Syntax:
./poke.ps1 HOST_IP PORT
If you want to test a range of ports just add an additional end to the port range as follows:
./poke.ps1 HOST_IP STARTPORT ENDPORT
It currently does only TCP, but could easily be adapted for UDP with a couple keystrokes.

If you want to add an alias so that you don’t have to type the ./ or .ps1 everytime, use the following instructions:

  • First you need to setup your powershell profile, if you haven’t done so already.
  • Create a directory where you want to keep your aliased scripts (I use c:\ps)
  • In your profile, add the following lines:
    $ps_script_dir = "c:\path\to\scripts"
    New-Alias <alias name> $ps_script_dir\<script name>
  • Open a new shell and you should be able to call your script by its alias

Additional Info
If you want to simply assign a one-liner, or a short snip of code to an alias, you don’t need to put it into a script file, as described above, you can simply create a function in your profile:

function someUsefulOneliner
{
    # your oneliner goes here
}
set-item -path alias:<alias name> -value someUsefulOneliner

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.