bash – 如何确定给定范围内的哪些IP具有使用nmap的端口80?

我完全不了解bash脚本,我正试图让这个工作:

扫描ip范围,查找端口80打开的设备…
我认为它必须如下所示:

#!/bin/bash
echo -----------------------------------
for ip in 192.168.0.{1,.255}; do
nmap -p80 192.168.0.1
      if #open; then
            echo "{ip} has the port 80 open"
      else
            #do nothing
fi
done
echo -----------------------------------
exit 0

我也只是想看到这样的结果:

-----------------------------------
192.168.0.1 has the port 80 open
192.168.0.10 has the port 80 open
192.168.0.13 has the port 80 open
192.168.0.15 has the port 80 open
-----------------------------------

(所以没有错误或nmap的正常输出..)

有人可以帮我吗?
谢谢

nmap带有一个很好的输出参数-oG(grepable output),这使得解析更容易.也不需要遍历所有要扫描的IP地址. nmap是网络掩码.

你的例子可以写成:

nmap -p80 192.168.0.0/24 -oG - | grep 80/open

-oG启用grepable输出,并且 – 指定要输出文件(在本例中为stdout).管道符号将nmap(stdout)的输出重定向到grep,在这种情况下,它只返回包含80 / open的行.

相关文章

用的openwrt路由器,家里宽带申请了动态公网ip,为了方便把2...
#!/bin/bashcommand1&command2&wait从Shell脚本并行...
1.先查出MAMP下面集成的PHP版本cd/Applications/MAMP/bin/ph...
1、先输入locale-a,查看一下现在已安装的语言2、若不存在如...
BashPerlTclsyntaxdiff1.进制数表示Languagebinaryoctalhexa...
正常安装了k8s后,使用kubect工具后接的命令不能直接tab补全...