【发布时间】:2014-02-07 08:33:52
【问题描述】:
我写了以下脚本:
#!/bin/bash
echo "Reading data - headers - both"
if [ $# -ne 3 ]; then
echo "Usage: ./nmap <port-range> <ip-list> <d || h || b>"
exit 1
fi
rm -f /tmp/right.txt 1>/dev/null 2>/dev/null
rm -f /tmp/wrong.txt 1>/dev/null 2>/dev/null
output=""
if [ $3 == h ]; then
while read -r -u3 port; do
while read -r -u4 ip; do
# echo -en "\n$ip $port: "
OUT=$( nmap -p "$port" --script=http-headers.nse "$ip" | awk 'NR>=7 && NR<=10')
# [[ $OUT == *Apache* ]] && $(echo -en "$ip $port\n" >> /tmp/right.txt) || $(echo -en "$ip $port\n" >> /tmp/wrong.txt)
[[ $OUT == *Apache* ]] && output="$output `echo -en "\n$ip -------------------- $port "`" && echo -e "$output" | column -t >> /tmp/right.txt || output="$output `echo -en "\n$ip -------------------- $port "`" && echo -e "$output" | column -t >> /tmp/wrong.txt
done 4< "$2"
done 3< "$1"
echo -e "$output" | column -t
elif [ $3 == d ]; then
echo data
elif [ $3 == b ]; then
echo both
fi
我希望我的输出有两个文件:
cat right.txt
ip1 ..... port1
ip2 ..... port1
ip2 ..... port2
ip3 ..... port3
.
.
.
cat wrong.txt
ip1 ..... port1
ip2 ..... port1
ip2 ..... port2
ip3 ..... port3
.
.
.
但它不能正常工作......
有什么想法吗?
提前谢谢你
【问题讨论】:
-
我会编辑我的帖子并输入我的真实输出
-
试试
[[ $OUT == *Apache* ]] && output="$outputecho -en "\n$ip -------------------- $port "" && echo -e "$output" | column -t > tee /tmp/right.txt /tmp/wrong.txt > /dev/null -
@JKB pardon..我会试试看..但如果您编辑我的脚本并在答案部分修改它,我也会非常感谢...
-
我已经更新了你的脚本对你有用吗?
-
@JKB 我去查一下