格式化nmap输出

问题描述 投票:1回答:1

我有一个nmap输出,看起来像这样

Nmap scan report for 10.90.108.82
Host is up (0.16s latency).

PORT   STATE SERVICE
80/tcp open  http
|_http-title: Did not follow redirect to https://10.90.108.82/view/login.html

我希望输出像

10.90.108.82 http-title:未遵循重定向到https://10.90.108.82/view/login.html

如何使用grep或任何其他方式完成?

grep nmap
1个回答
0
投票

您可以使用以下nmap.sh脚本:

<nmap_command> | ./nmap.sh

nmap.sh:

#!/usr/bin/env sh

var="$(cat /dev/stdin)"
file=$(mktemp)
echo "$var" > "$file"

ip_address=$(head -1 "$file" | rev | cut -d ' ' -f1 | rev)
last_line=$(tail -1 "$file" | sed -E "s,^\|_, ,")

printf "%s%s\n" "$ip_address" "$last_line"
rm "$file"
© www.soinside.com 2019 - 2024. All rights reserved.