使用 nmap 遍历每个 ip?

Use nmap to loop over each ip?

我正在寻找一种方法来清理 nmap 的输出并循环遍历每个 ip 运行 ssh pi@<ip> 直到找到匹配项。这可能吗?我一直在四处寻找,但我找不到任何人在 nmap 输出上循环的情况?

我得到的最接近的是:

➜ nmap -n -sP xxx.xxx.x.13/24 | grep "Nmap scan report for"  
Nmap scan report for xxx.xxx.x.1
Nmap scan report for xxx.xxx.x.2
Nmap scan report for xxx.xxx.x.6
Nmap scan report for xxx.xxx.x.7
Nmap scan report for xxx.xxx.x.9
Nmap scan report for xxx.xxx.x.10
Nmap scan report for xxx.xxx.x.11
Nmap scan report for xxx.xxx.x.13
Nmap scan report for xxx.xxx.x.19
Nmap scan report for xxx.xxx.x.22

I am looking for a way to clean up nmap's output

nmap -n -sP xxx.xxx.x.13/24 | awk '/^Nmap scan report for [[:digit:].]+$/ {print $NF}'

and loop over each ip running ssh pi@ for each until a match is found. Is this possible?

可能是 while read 循环?

#!/usr/bin/env bash

while read -ru9 ips; do
  ssh "pi@$ips"
done 9< <(nmap -n -sP xxx.xxx.x.13/24 | 
  awk '/^Nmap scan report for [[:digit:].]+$/ {print $NF}'
)