使用nmap遍历每个IP?

时间:2020-06-28 05:26:45

标签: bash loops nmap

我正在寻找一种清理nmap输出并循环运行每个ssh pi@<ip>的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

1 个答案:

答案 0 :(得分:1)

我正在寻找一种清理nmap输出的方法

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

并遍历每个运行ssh pi @的IP,直到找到匹配项。这可能吗?

也许有一个读取循环?

#!/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}'
)