Results 1 to 10 of 11

Thread: HOWTO: Netcat - TCP/IP swiss army knife

Threaded View

  1. #1
    Join Date
    Jul 2007
    Ubuntu 9.04 Jaunty Jackalope

    HOWTO: Netcat - TCP/IP swiss army knife

    This article describes some netcat applications and demonstrates how to use netcat which is one of the most useful network tools.

    0. HTTP Server
    This is a simple HTTP server which listens on port 8080. The -l option puts netcat into listen mode and -c specifies the command to execute after a connection is established. The server respond can be viewed with a browser at http://localhost:8080.
            read req file proto
            echo -e "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n"
            echo -e "<html><h1>Hello World</h1></html>"
    typeset -fx handle_req
    nc -l -p 8080 -c handle_req
    1. HTTP Client
    This example will fetch the latest kernel version from (similar to finger(1) ). Note that netcat prints also the HTTP header.
    echo -e "GET /kdist/finger_banner HTTP/1.0\r\n" | \
    nc 80 | grep latest
    2. Remote Terminal
    This example shows how to connect to a remote shell without using telnet or ssh. The terminal server which runs on <host>:
    nc -l -p 4000 -e /bin/sh
    and the client :
    nc <host> 4000
    3. Port Scanning
    netcat can also be used for port scanning (with zero-I/O option).
    nc -v -z 80 21
    # or with port ranges
    nc -v -z 21-23
    4. File Transfer
    Sending a file "foobar" on port 4000 can be achieved like this:
    cat foobar | nc -l -p 4000
    The client would receive the file from <host> with this command:
    nc <host> 4000 > foobar
    5. Torifying Netcat
    The tor package includes torify, a wrapper for tsocks and tor, which can be used to anonymize network traffic :
    echo -e "GET /iponly/ HTTP/1.0\r\n" | torify nc 80
    This should print the IP address of the Tor exit-node that is used.

    6. Chat
    A simple one-to-one chat server can be started like this:
    nc -lp 8080
    Afterwards a client can connect to the server:
    nc <host> 8080
    Last edited by uljanow; July 15th, 2009 at 11:30 PM. Reason: added chat server

    "Specialization is for Insects", R. Heinlein

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts