# Nmap Commands

## Nmap Scan Top Ports

```python
nmap -A -v --top-ports 20
```

### Nmap Scan on List of Hosts

```
nmap -A -v -iL Hosts.txt -oN output.txt
```

## Masscan

Massscan full port scan for TCP and UDP Both

```python
masscan -p1-65535,U:1-65535 --rate=1000 10.10.10.74 -e tun0  
```

## Rustscan with Nmap (Fast Port Scanning)

This command Finds out Open Ports Quicky, then Passes the ports to Nmap with -A Flag to do Aggressive Scan

```python
rustscan -a 10.10.68.208 -- -A # Single IP

rustscan -a 192.168.1.1,192.168.1.2,192.168.1.3 -- -A  # Multiple IPs

```

<figure><img src="/files/lPnGMjDpHD99RHDdnTSo" alt=""><figcaption></figcaption></figure>

## Get IP, MAC && Vendor Name

```python
 nmap -sn 172.26.10.0/24 | grep -E "Nmap scan report|MAC Address" | awk '/Nmap scan report/ {ip=$5} /MAC Address/ {print ip, $3, $4, $5}'
```

<figure><img src="/files/whQOseggqAMMcpiz7sh7" alt=""><figcaption></figcaption></figure>

## Get Only IP IPaddress

```python
nmap -sn 172.26.10.0/24 | grep "Nmap scan report" | awk '{print $5}'
```

<figure><img src="/files/FgxtJy7KEecb0JFdNqto" alt=""><figcaption></figcaption></figure>

## Port Scan Script On all Ips

```python
while read ip; do        
  echo "Port scan for $ip:" >> port_scan_results.txt
  nmap -A $ip >> port_scan_results.txt      
  echo "------------------------" >> port_scan_results.txt
done < ips.txt

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://notes.programmersecurity.com/network-penetration-testing/nmap-commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
