使用 nmap 在一行中获取 header 名称和 ip

get header name and ip in one line using nmap

H;

我正在尝试使用 Nmap 在一行中获取 header 名称和 IP 地址,但我没有找到执行此操作的好方法 我试过了:(以我的路由器为例):

我正在使用 SSH

nmap -sS -n -p80 192.168.2.1 --script=http-headers -T5 --min-rate 1000 --max-retries 0

输出:

Nmap scan report for 192.168.2.1
Host is up (0.12s latency).
PORT   STATE SERVICE
80/tcp open  http
| http-headers:
|   WWW-Authenticate: Basic realm="TD-W8901G"
|   Content-Type: text/html
|   Transfer-Encoding: chunked
|   Server: RomPager/4.07 UPnP/1.0
|   Connection: close
|   EXT:
|
|_  (Request type: GET)

我正在寻找的输出是:

192.168.2.1 => TD-W8901G or 
192.18.2.1:TD-W8901G

此致

像这样 awk:

nmap ... | awk '/^Nmap/{ip=$NF} /realm=/{gsub(/"/,"",$NF);gsub(/.*=/,"",$NF);print ip,$NF;exit}'

也就是说... "if the line starts with "Nmap", 将最后一个字段保存在变量 ip 中。如果该行包含 "realm=",则删除所有双引号和去除等号之前的所有内容。打印 ip 和最后一个剩余字段,然后退出。“.