如何使用 nmap 确定给定范围内的哪些 IP 具有端口 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
的正常输出..)
有人可以帮助我吗?
I'm new to bash scripting and I'm trying to get this working:
Scanning an IP range for finding devices with the port 80 open...
I think it has to look like this:
#!/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
I also just want to see the results like this:
-----------------------------------
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
-----------------------------------
(So without errors or nmap
's normal outputs..)
Can someone help me for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
nmap
附带了一个很好的输出参数-oG
(grepable 输出),这使得解析更加容易。此外,无需遍历所有要扫描的 IP 地址。 nmap 可以识别网络掩码。您的示例可以写为:
-oG
启用 grepable 输出,并且-
指定要输出到的文件(在本例中标准输出
)。管道符号将 nmap (stdout) 的输出重定向到 grep,在这种情况下,它仅返回包含80/open
的行。nmap
comes with a nice output parameter-oG
(grepable output) which makes parsing more easy. Also it is not necessary to iterate through all IP addresses you want to scan. nmap is netmask aware.Your example can be written as:
The
-oG
enables the grepable output, and-
specifies the file to output to (in this casestdout
). The pipe symbol redirects the output of nmap (stdout) to grep, which only returns lines containing80/open
in this case.试试这个
--open
将仅列出端口 80 打开的主机。这样您就不必签入 shell 脚本,因为过滤已经由 nmap 本身完成。https://nmap.org/book/man-briefoptions.html
Try this
The
--open
will only list host with port 80 open. This way you save having to check in your shell script as filtering is already done by nmap itself.https://nmap.org/book/man-briefoptions.html