Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save simz0ff/1a47c0d4fa6dd3df5c76fd58aa792c7e to your computer and use it in GitHub Desktop.
Save simz0ff/1a47c0d4fa6dd3df5c76fd58aa792c7e to your computer and use it in GitHub Desktop.

Revisions

  1. @Khoulaiz Khoulaiz revised this gist Jun 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -64,4 +64,4 @@ print "connected to the server\n";
    connected to the server
    ```
    Credits to (skohrs)[http://serverfault.com/users/128800/skohrs]
    Credits to [skohrs](http://serverfault.com/users/128800/skohrs)
  2. @Khoulaiz Khoulaiz revised this gist Jun 30, 2015. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ bash: connect: Connection refused
    bash: /dev/tcp/127.0.0.1/23: Connection refused
    ```
    cURL
    ~~~~
    ----
    ```
    $ curl -v telnet://127.0.0.1:22
    * About to connect() to 127.0.0.1 port 22 (#0)
    @@ -29,7 +29,7 @@ $ curl -v telnet://127.0.0.1:23
    curl: (7) couldn't connect to host
    ````
    Python
    ======
    ------
    ```
    # python
    Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
    @@ -48,7 +48,7 @@ Traceback (most recent call last):
    socket.error: [Errno 111] Connection refused
    ```
    Perl
    ====
    ----
    ```
    # perl
    use IO::Socket::INET;
    @@ -62,4 +62,6 @@ die "cannot connect to the server $!\n" unless $socket;
    print "connected to the server\n";
    ^D
    connected to the server
    ```
    ```
    Credits to (skohrs)[http://serverfault.com/users/128800/skohrs]
  3. @Khoulaiz Khoulaiz revised this gist Jun 30, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    Here are several different ways to test a TCP port without telnet.

    BASH [(man page)](http://linux.die.net/man/1/bash)
    ================================================
    --------------------------------------------------
    ```
    $ cat < /dev/tcp/127.0.0.1/22
    SSH-2.0-OpenSSH_5.3
    @@ -12,7 +12,7 @@ bash: connect: Connection refused
    bash: /dev/tcp/127.0.0.1/23: Connection refused
    ```
    cURL
    ====
    ~~~~
    ```
    $ curl -v telnet://127.0.0.1:22
    * About to connect() to 127.0.0.1 port 22 (#0)
  4. @Khoulaiz Khoulaiz revised this gist Jun 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    Here are several different ways to test a TCP port without telnet.

    BASH [man page](http://linux.die.net/man/1/bash)
    BASH [(man page)](http://linux.die.net/man/1/bash)
    ================================================
    ```
    $ cat < /dev/tcp/127.0.0.1/22
  5. @Khoulaiz Khoulaiz revised this gist Jun 30, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    Here are several different ways to test a TCP port without telnet.

    BASH (man page)
    ===============
    BASH [man page](http://linux.die.net/man/1/bash)
    ================================================
    ```
    $ cat < /dev/tcp/127.0.0.1/22
    SSH-2.0-OpenSSH_5.3
  6. @Khoulaiz Khoulaiz renamed this gist Jun 30, 2015. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions gistfile1.asciidoc → gistfile1.md
    Original file line number Diff line number Diff line change
    @@ -2,18 +2,18 @@ Here are several different ways to test a TCP port without telnet.

    BASH (man page)
    ===============
    ````
    ```
    $ cat < /dev/tcp/127.0.0.1/22
    SSH-2.0-OpenSSH_5.3
    ^C
    $ cat < /dev/tcp/127.0.0.1/23
    bash: connect: Connection refused
    bash: /dev/tcp/127.0.0.1/23: Connection refused
    ````
    ```
    cURL
    ====
    ````
    ```
    $ curl -v telnet://127.0.0.1:22
    * About to connect() to 127.0.0.1 port 22 (#0)
    * Trying 127.0.0.1... connected
    @@ -27,10 +27,10 @@ $ curl -v telnet://127.0.0.1:23
    * couldn't connect to host
    * Closing connection #0
    curl: (7) couldn't connect to host
    `````
    ````
    Python
    ======
    ````
    ```
    # python
    Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
    [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
    @@ -46,10 +46,10 @@ Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "<string>", line 1, in connect
    socket.error: [Errno 111] Connection refused
    ````
    ```
    Perl
    ====
    ````
    ```
    # perl
    use IO::Socket::INET;
    $| = 1;
    @@ -62,4 +62,4 @@ die "cannot connect to the server $!\n" unless $socket;
    print "connected to the server\n";
    ^D
    connected to the server
    ````
    ```
  7. @Khoulaiz Khoulaiz revised this gist Jun 30, 2015. 1 changed file with 12 additions and 11 deletions.
    23 changes: 12 additions & 11 deletions gistfile1.asciidoc
    Original file line number Diff line number Diff line change
    @@ -2,35 +2,35 @@ Here are several different ways to test a TCP port without telnet.

    BASH (man page)
    ===============

    # cat < /dev/tcp/127.0.0.1/22
    ````
    $ cat < /dev/tcp/127.0.0.1/22
    SSH-2.0-OpenSSH_5.3
    ^C

    # cat < /dev/tcp/127.0.0.1/23
    $ cat < /dev/tcp/127.0.0.1/23
    bash: connect: Connection refused
    bash: /dev/tcp/127.0.0.1/23: Connection refused

    ````
    cURL
    ====

    # curl -v telnet://127.0.0.1:22
    ````
    $ curl -v telnet://127.0.0.1:22
    * About to connect() to 127.0.0.1 port 22 (#0)
    * Trying 127.0.0.1... connected
    * Connected to 127.0.0.1 (127.0.0.1) port 22 (#0)
    SSH-2.0-OpenSSH_5.3
    ^C

    # curl -v telnet://127.0.0.1:23
    $ curl -v telnet://127.0.0.1:23
    * About to connect() to 127.0.0.1 port 23 (#0)
    * Trying 127.0.0.1... Connection refused
    * couldn't connect to host
    * Closing connection #0
    curl: (7) couldn't connect to host

    `````
    Python
    ======

    ````
    # python
    Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
    [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
    @@ -46,10 +46,10 @@ Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "<string>", line 1, in connect
    socket.error: [Errno 111] Connection refused

    ````
    Perl
    ====

    ````
    # perl
    use IO::Socket::INET;
    $| = 1;
    @@ -62,3 +62,4 @@ die "cannot connect to the server $!\n" unless $socket;
    print "connected to the server\n";
    ^D
    connected to the server
    ````
  8. @Khoulaiz Khoulaiz created this gist Jun 30, 2015.
    64 changes: 64 additions & 0 deletions gistfile1.asciidoc
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,64 @@
    Here are several different ways to test a TCP port without telnet.

    BASH (man page)
    ===============

    # cat < /dev/tcp/127.0.0.1/22
    SSH-2.0-OpenSSH_5.3
    ^C

    # cat < /dev/tcp/127.0.0.1/23
    bash: connect: Connection refused
    bash: /dev/tcp/127.0.0.1/23: Connection refused

    cURL
    ====

    # curl -v telnet://127.0.0.1:22
    * About to connect() to 127.0.0.1 port 22 (#0)
    * Trying 127.0.0.1... connected
    * Connected to 127.0.0.1 (127.0.0.1) port 22 (#0)
    SSH-2.0-OpenSSH_5.3
    ^C

    # curl -v telnet://127.0.0.1:23
    * About to connect() to 127.0.0.1 port 23 (#0)
    * Trying 127.0.0.1... Connection refused
    * couldn't connect to host
    * Closing connection #0
    curl: (7) couldn't connect to host

    Python
    ======

    # python
    Python 2.6.6 (r266:84292, Oct 12 2012, 14:23:48)
    [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import socket
    >>> clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    >>> clientsocket.connect(('127.0.0.1', 22))
    >>> clientsocket.send('\n')
    1
    >>> clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    >>> clientsocket.connect(('127.0.0.1', 23))
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "<string>", line 1, in connect
    socket.error: [Errno 111] Connection refused

    Perl
    ====

    # perl
    use IO::Socket::INET;
    $| = 1;
    my $socket = new IO::Socket::INET(
    PeerHost => '127.0.0.1',
    PeerPort => '22',
    Proto => 'tcp',
    );
    die "cannot connect to the server $!\n" unless $socket;
    print "connected to the server\n";
    ^D
    connected to the server