# What is Netcat?

Netcat is a **command line tool** responsible for reading and writing data in the network. To exchange data, Netcat uses the network protocols [TCP/IP](https://www.ionos.co.uk/digitalguide/server/know-how/an-introduction-to-tcpip/ "An introduction to TCP/IP") and [UDP](https://www.ionos.co.uk/digitalguide/server/know-how/udp-user-datagram-protocol/ "UDP - User Datagram Protocol"). The tool originally comes from the [world of Unix](https://www.ionos.co.uk/digitalguide/server/know-how/unix-a-history/ "Unix: a history") but is now **available for all platforms**.

Due to its universal usability, Netcat is often called the “Swiss army knife for TCP/IP”. For instance, it allows you to diagnose faults and problems that jeopardise the functionality and security of a network. Port scans, data streaming or simple data transfers can also be performed by Netcat. What’s more, chat, and web servers can be set up and mail requests started. The streamlined software – already developed in the mid-1990s – can operate in **server and client mode**.

## How do I use Netcat?

Netcat can be used on all platforms via the **command line**. The command line tool is usually pre-installed on Linux and macOS. Windows users need to download the program from the internet. Special installation steps are not necessary; downloading the program file (*nc.exe*) is enough for use on Windows. You can then use Netcat with **command prompt** (*cmd.exe*) to carry out various network tasks. Start the command prompt as follows:

1. Press the key combination \[Windows\] + \[R\]
2. Enter “cmd” into the entry field (1)
3. Press the “OK” button (2)

[![Image: Starting the command prompt via the “Run” window](https://www.ionos.co.uk/digitalguide/fileadmin/_processed_/e/d/csm_netcat-1_b81562a44f.webp "Starting the command prompt via the “Run” window")](https://www.ionos.co.uk/digitalguide/fileadmin/DigitalGuide/Screenshots_2020/netcat-1.png) Starting the command line for entering Netcat commands       After doing so, the *cmd.exe* will open with the following screen:

[![Image: Command prompt start screen](https://www.ionos.co.uk/digitalguide/fileadmin/_processed_/3/0/csm_netcat-2_545779cf02.webp "Command prompt start screen")](https://www.ionos.co.uk/digitalguide/fileadmin/DigitalGuide/Screenshots_2020/netcat-2.png) Start screen of the command prompt; “USERNAME” is a placeholder that refers to the active user account.       To start the program file (*nc.exe*), you also need to **switch to the storage location**. If the *nc.exe* is saved in the “netcat” folder on the Windows desktop, the syntax will look like this:

```none
cd C:\Users\USERNAME\Desktop\netcat\
```

The command “**cd**” (**change directory**) activates the switchover; the underlying program path addresses the storage folder of the *nc.exe* file. The switchover looks like this in the command line:

[![Image: Switching folders in the command line](https://www.ionos.co.uk/digitalguide/fileadmin/_processed_/d/6/csm_netcat-3_c2c956f2f7.webp "Switching folders in the command line")](https://www.ionos.co.uk/digitalguide/fileadmin/DigitalGuide/Screenshots_2020/netcat-3.png) Switching to the program folder of Netcat by entering the command “cd”       Netcat requires **advanced access rights** for a number of operations. In Windows 10, the command prompt can be launched in just a few steps with administrator rights:

1. Right-click on the Windows symbol in the left of the task bar or press the key combination \[Windows\] + \[X\]
2. Select “Command Prompt (Admin)” in the context menu that appears:

[![Image: Starting Netcat with administrator rights](https://www.ionos.co.uk/digitalguide/fileadmin/_processed_/3/3/csm_netcat-4_72604693e5.webp "Starting Netcat with administrator rights")](https://www.ionos.co.uk/digitalguide/fileadmin/DigitalGuide/Screenshots_2020/netcat-4.png) Starting the command prompt with administrator rights via the context menu of the Windows task bar       ---

### Note

Using Netcat involves certain security risks. For this reason, the tool should only be used by experienced users and system administrators – especially in the mode with advanced access rights.

---

## Netcat syntax: what commands and options exist?

Netcat syntax is made up of two basic components: the constant base command “**nc**”, followed by various “**options**”. The base command addresses the program file *nc.exe.*, while the options determine the specific functional scope of a Netcat version. Depending on the operating system and Netcat version used, the possibilities vary.

The following table only covers the **main options** available in most versions for Linux, macOS, and Windows. Moreover, additional useful options are listed – in particular extensions based on the widespread **GNU Netcat version** for Linux, Unix, and macOS:

<table>
  <tbody>
    <tr>
      <td><strong>Options</strong></td>
      <td><strong>Description</strong></td>
    </tr>
    <tr>
      <td>-4</td>
      <td>Forces the use of IPv4 (GNU Netcat)</td>
    </tr>
    <tr>
      <td>-6</td>
      <td>Forces the use of IPv6 (GNU Netcat)</td>
    </tr>
    <tr>
      <td>-d</td>
      <td>Releases Netcat from the console (running in the background; available in Windows and current GNU Netcat versions)</td>
    </tr>
    <tr>
      <td>-D</td>
      <td>Activates the option for debugging sockets (GNU Netcat)</td>
    </tr>
    <tr>
      <td>-h (display help)</td>
      <td>Displays help (commands/options with a short description)</td>
    </tr>
    <tr>
      <td>-i (secs)</td>
      <td>Delays in seconds for sent lines or scanned ports</td>
    </tr>
    <tr>
      <td>-k</td>
      <td>At the end of a connection, Netcat waits for a new connection (only possible with GNU Netcat and only in combination with “-l”)</td>
    </tr>
    <tr>
      <td>-l (listen mode)</td>
      <td>Listen and server mode for incoming connection requests (via port indicated)</td>
    </tr>
    <tr>
      <td>-L Listen harder</td>
      <td>Netcat also continues to operate in listen mode after client-side connection terminations (consistently with the same parameters; only supported by the Windows version)</td>
    </tr>
    <tr>
      <td>-n (numeric only)</td>
      <td>Only IP numbers, no DNS names</td>
    </tr>
    <tr>
      <td>-o (file)</td>
      <td>A hex dump is carried out for the data traffic (content of files represented in a hexadecimal view); used for fault finding (debugging network applications); recording/sniffing communication is possible (for outgoing and incoming packages)</td>
    </tr>
    <tr>
      <td>-p (port)</td>
      <td>Enters the local source port that Netcat should use for outgoing connections</td>
    </tr>
    <tr>
      <td>-r</td>
      <td>Use of random port values when scanning (for local and remote ports)</td>
    </tr>
    <tr>
      <td>-s (address)</td>
      <td>Defines the local source address (IP address or name)</td>
    </tr>
    <tr>
      <td>-t</td>
      <td>Telnet mode (enables server contact via Telnet); requires a special compilation of Netcat, otherwise the option is not available.</td>
    </tr>
    <tr>
      <td>-u</td>
      <td>Use of UDP mode (instead of TCP)</td>
    </tr>
    <tr>
      <td>-U (gateway)</td>
      <td>Netcat uses Unix domain sockets (GNU Netcat)</td>
    </tr>
    <tr>
      <td>-v</td>
      <td>Extensive output (e.g. responsible for the display and scope of displayed fault messages)</td>
    </tr>
    <tr>
      <td>-w (secs)</td>
      <td>Defines timeouts; for establishing and terminating connections (unit: seconds)</td>
    </tr>
    <tr>
      <td>-z</td>
      <td>Port scanner mode (zero I/O mode); only listening services are scanned (no data is sent)</td>
    </tr>
  </tbody>
</table>

A simple example for the use of the Netcat syntax is for accessing help with the parameter “-h”:

```none
C:\Users\USERNAME\Desktop\netcat>nc -h
```

[![Image: Accessing Netcat help](https://www.ionos.co.uk/digitalguide/fileadmin/_processed_/7/3/csm_netcat-5_a109c6c588.webp "Accessing Netcat help")](https://www.ionos.co.uk/digitalguide/fileadmin/DigitalGuide/Screenshots_2020/netcat-5.png) Accessing help in the Windows command prompt results in a list of available Netcat options.       For instance, if you want to define a **server** or a **client** in the network for data transmission, the following syntax applies:

Client mode (connect to somewhere):

```none
nc [options] [IP address/host name] [port]
```

Server mode (listen for inbound):

```none
nc -l -p port [options] [host name] [port]
```

The fundamental structure for **running a port scan** is as follows:

```none
nc [options] [host] [port]
```

## Copying files with Netcat

A **frequently used feature** of Netcat is copying files. Even large quantities of data can be sent and individual partitions or entire hard drives cloned. In our example, the *testfile.txt* file is copied from computer A (client) to computer B (server) via port 6790: These steps are required:

1. Determine the IP address of computer B (destination PC)
2. **Create the test file** *testfile.txt* in the Netcat folder of computer A; in this example, the fest file is located in the client’s Netcat folder. The copied file then ends up in the Netcat folder on computer B (other file paths need to be adjusted accordingly).
3. Enter the Netcat syntax in the command line

Computer B (acts as the receiving server):

```none
nc -l -p 6790 > testfile.txt
ENTER
```

Computer A (acts as the sending client):

```none
nc [IP address of computer B] 6790 < testfile.txt
ENTER
```

The success of the transfer is **not confirmed in the command prompt**. You can see whether the transfer worked by checking in the destination folder.

## Running port scans

In order to **detect any errors and security issues**, you can run a scan and identify **open ports**. In the following example, the computer has the IP address *192.168.11.1.* After the IP address, individual ports (e.g. 1), multiple ports (1, 2, 3 etc.) or a whole range (1-1024) can be entered for the scan:

```none
nc -w 2 -z 192.168.10.1 1-1024
```

The option “-w” sets the **timeout** (here: “try to establish a connection with the ports for two seconds”). The option “-z” instructs Netcat to only search for listening services and not to send any data.

If the option “-v” is added, you will obtain **detailed information** about the scan:

```none
nc -v -w 2 -z 192.168.11.1 1-1024
```

Netcat confirms the detection of an open port with the message “succeeded!”:

```none
Connection to 192.168.11.1 25 port [tcp/smtp] succeeded!
```

Most **familiar services** such as email, FTP or SSH run on the scanned ports 1–1024. In this example, Netcat has found the open SMTP port of an email client.

## Netcat as a simple chat program

Netcat can also set up a **simple TCP or UDP connection** between two computers and open up a communication channel. In the example below, the recipient is first installed on the **remote system** and set to listening mode. The recipient then acts as “listener” and uses the port 1605 to receive messages. They can be reached at the IP address *192.168.11.1.*

```none
nc -l -p 1605
ENTER
```

A **connection** is then established by the local computer (sending PC) **with the message recipient** using the following command:

```none
nc 192.168.11.1 1605
ENTER
```

If the connection is successfully established, messages can be sent in **both directions**.

## Setting up a simple web server

Netcat can also be used to set up a **simple web server**. If the established server can’t be reached due to technical problems, for example, you can at least respond to requests with a **prepared failure message** (in the form of a html file):

```none
nc -l -v -p 85 -w10 -L < failuremessage.html
```

Netcat waits for requests sent to port 85 and responds with the file *failuremessage.html*. The option “-L” allows you to maintain the Netcat process **beyond** **a single request**. The parameter “-w” terminates the connection after 10 seconds (timeout). The “-v” parameter gives the server operator **information about the requests** and documents the operating system and browser type of the requesting client computer, for example, by means of status messages.

## Is Netcat a security risk?

Undoubtedly, Netcat can be used universally in networks and performs many helpful tasks here. So, it’s no wonder that it is extremely popular among system and network administrators – particularly since creating Netcat code becomes relatively easy after a certain amount of time.

But there is also a downside: Netcat is a **hacking tool** used for spying on networks, seeking out vulnerabilities, circumventing fire walls, and exploiting backdoors for taking over computers. Anti-virus programs sound the alarm, for example, when a Netcat version is found on the computer which enables execution of the **option “-e”** due to a special compilation.

Using this “-e” in the code, an **interactive interface (backdoor shell)** can be started on a remote computer. Anyone who gains unrestricted access to the *cmd.exe* on Windows can inflict a significant amount of damage. Additional [malware](https://www.ionos.co.uk/digitalguide/server/security/how-to-recognize-and-remove-malware/ "How to recognize and remove malware") can also be loaded via a backdoor shell. Hackers often use the Netcat parameter “-d” in the code, which allows the command prompt tool to cause trouble on Windows computers – while running invisibly in the background.

To avoid hacked versions, Netcat should only be downloaded from **safe sources** on the internet. Security experts also advise careful consideration on whether a tool like Netcat is even needed in the **installation scope of systems** (particularly frontend systems).

Another security risk: Netcat generally transmits data in **clear text without encryption**. For this reason, the tool should only be used in networks that are very well protected or – even better – cut off from the internet. For data transfers on the internet, the Netcat successor **Cryptcat** is better suited since it encrypts the data. Moreover, connections can be tunneled via [SSH](https://www.ionos.co.uk/digitalguide/server/tools/ssh-secure-shell/ "SSH: Secure Shell") when transmitting security-relevant data.

The advantages and potential risks clearly show that Netcat is a tool which well-versed users, system administrators, and **IT managers** should carefully consider. Those who understand the advantages can benefit from the versatility and efficiency of the remote administration tool. And those who can suitably assess the dangers for the security of their own network, can take preventive measures to stop hacking attacks – or at least contain the damage.

However, the tool is now rather **outdated** – having emerged in hacking circles over 20 years ago. Better tools exist for a range of network activities. Besides Cryptcat, **Socat** is worth mentioning. It can use the network protocol [SCTP](https://www.ionos.co.uk/digitalguide/server/know-how/sctp/ "SCTP") in addition to TCP and UDP, works via [proxy servers](https://www.ionos.co.uk/digitalguide/server/know-how/what-is-a-proxy-server/ "What is a proxy server?"), and supports encryption. It also runs on all common platforms like Netcat.

But Netcat continues to enjoy **special status** as a streamlined and rapidly deployable **all-rounder** with simple command syntax. In combination with the administration tool Netsh, for example, many more options can be used for efficient network diagnostics and management.


This is a markdown version of: [https://www.ionos.co.uk/digitalguide/server/tools/netcat/](https://www.ionos.co.uk/digitalguide/server/tools/netcat/) for AI/LLM consumption.