Example

One Line Network Port Checker

Author: Carl Sassenrath
Return to REBOL Cookbook

If you run your own servers or network, you often find you need to quickly test if a service is reachable on a specific TCP port. Here is an easy way to perform such a check from the console:


    close open tcp://demo.rebol.net:80

This line opens a TCP/IP connection to the demo.rebol.net server on port 80 (the web server port in this case). If the web server is down, the OPEN will fail, and you will see an error. If it opened okay, then no error will be shown.

If you want to use this code in a script (rather than just the console), just wrap it in a TRY block, such as:


    if error? try [
        close open tcp://demo.rebol.net:80
    ][
        print "server is down"
    ]

Note

This isn't a perfect test. It is possible that a service can be in a state where it allows a port to open, but cannot perform the rest of its operations. This test is useful for non-critical applications, such as configuring firewalls, testing server setups, and other monitoring operations.


2006 REBOL Technologies REBOL.com REBOL.net