如何编写bash脚本来搜索文件中的IP并将其写入另一个文件?
我需要编写一个 bash 脚本,该脚本将采用一个可 grepable nmap 输出文件,该文件显示端口 80 打开的 IP 地址,并将端口 80 打开的 IP 复制到另一个文本文件。输出看起来与此类似:
# Nmap 4.76 scan initiated Thu Dec 3 13:36:29 2009 as: nmap -iL ip.txt -p 80 -r -R -PN --open -oA output
Host: 192.168.1.100 () Status: Up
Host: 192.168.1.100 () Ports: 80/open/tcp//http///
Host: 192.168.1.100 () Status: Up
# Nmap done at Thu Dec 3 13:36:29 2009 -- 3 IP addresses (3 hosts up) scanned in 0.28 seconds
我对 bash 脚本相当陌生,所以我不知道从哪里开始。如果您能帮助我完成这个脚本,我将不胜感激。
I need to write a bash script that will take a grepable nmap output file that displays IP addresses with port 80 open and copy the IPs that have port 80 open to another text file. The output looks similar to this:
# Nmap 4.76 scan initiated Thu Dec 3 13:36:29 2009 as: nmap -iL ip.txt -p 80 -r -R -PN --open -oA output
Host: 192.168.1.100 () Status: Up
Host: 192.168.1.100 () Ports: 80/open/tcp//http///
Host: 192.168.1.100 () Status: Up
# Nmap done at Thu Dec 3 13:36:29 2009 -- 3 IP addresses (3 hosts up) scanned in 0.28 seconds
I am fairly new to bash scripting so I am not sure where to start with this. If you can help me with this script it would be much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可以简化为 awk 调用:
this can be reduced to an awk call:
使用 grep 和 sed/awk
将是我的第一次尝试。
Use grep and sed/awk
would be my first attempt.
不熟悉 nmap 调用和输出格式,但这仍然应该有效:
not being familiar with nmap invocation and output format, but still, this should work: