OSX has a command line port scanner. It’s just super sekrit is all. The questionably named stroke command, is part of Network Utility, which is nestled in your Utilities folder. Normally it’s only exposed through Network Utility’s GUI, but there is a way to get at it from your command prompt.

First, create a link to stroke, preferably somewhere in your $PATH.

ian@mymac:~$ ln /Applications/Utilities/Network\ Utility.app/Contents/Resources/stroke stroke

Next make it executable, if it isn’t already.

ian@mymac:~$ chmod uo+x stroke

Now let’s do a port scan. We will scan the localhost, ports 49152 thru 65535.

ian@mymac:~$ ./stroke 127.0.0.1 49152 65535

Can you install nmap, or even nessus instead? Absolutely. But in an, ehrm, pinch — stroke will do nicely.

Technorati Tags: , , , , , ,

11 Responses to “OSX Has a Builtin Command Line Port Scanner”

  1. Nicolas Toper Says:

    Thanks for this tips. This is very useful for me. Thanks

  2. Rick (UK) Says:

    Great tip – ta very much

  3. Abhi Says:

    Yeah this was awesome! Thanks.

  4. Abhi Says:

    Ok so this is a n00b questions but I found a few tcp ports open and I wanna close them. How would I do that?
    Thanks again.

  5. Lanny Says:

    SUPER HINT! Thanks a 10^6

  6. Lyon T Says:

    Great tip!

    Very useful!

  7. Joe Says:

    Thanks for pointing that out! I’d like to suggest an alternative method though

    sudo ln -s /Applications/Utilities/Network\ Utility.app/Contents/Resources/stroke /usr/local/bin/stroke

    1. Soft-link to it for safety
    2. Place linked file in /usr/local/bin so you can use it anywhere
    3. Keeps the binary out of your ~/ home directory
    4. No need to chmod or ./ the binary

    user$ stroke 127.0.0.1 49152 65535

    Cheers!

  8. Antonio Nesic Says:

    Brilliant. Saved me a lot of time :)

  9. Kevin Says:

    Where are the results after executing the command?

  10. Kevin Says:

    Got it. Helps to scan a node with actual ports open :)

    bash-3.2# ./stroke http://www.google.com 80 80
    Port Scanning host: 74.125.224.145

    Open TCP Port: 80 http

  11. neildaemond Says:

    cool! nice little tip!

Leave a Reply