从具体的线路输出和猫搜索到特定的行并重新搜索 [英] search in output and cat from specific line to specific line and search again

查看:70
本文介绍了从具体的线路输出和猫搜索到特定的行并重新搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的是这样的:

  OUT = $(NMAP -p$端口--script = HTTP-headers.nse$ IP

例如输出是:

  | HTTP报头:
|服务器:Apache
|有所不同:接受编码
|内容类型:text / html的;字符集= UTF-8
|日期:星期四,2014年2月6日7时31分33秒GMT
|年龄:25
|连接:关闭

但我的输出的长度是可变的。
所以我想要的东西在我的输出线之间的搜索(最好使用 SED AWK
 检查的条件。例如,如果它看到的Apache 从3线到8号线则回声右键

编辑:

我的脚本:

 #!/斌/庆典回声读取数据 - 标题 - 既如果[$#-ne 3];然后
    回声用法:./nmap<港口范围>< IP-列表>< d || ^ h || B>中
    1号出口
科幻如果[$ 3 == H];然后
    而读-r -u3端口;做
    而阅读-r IP -u4;做
        回声-n$ IP $端口
        OUT = $(NMAP -p$端口--script = HTTP-headers.nse$ IP|
        尾-n 13 |
        awk的-F:'{打印$ 2;在其他线路退出}')
        [[$ OUT == *阿帕奇*]]&放大器;&放大器;回声右||回声错
    完成4℃; $ 2
    做3'; $ 1ELIF [$ 3 = D]。然后
    回波数据
ELIF [$ 3 == B];然后
    既呼应
科幻

我希望把我正确的结果在文件...例如:

 猫right.txt
IP1端口1
IP2 PORT2猫wrong.txt
IP1端口1
IP2 PORT2


解决方案

下面是修复

 #!/斌/庆典回声读取数据 - 标题 - 既如果[$#-ne 3];然后
    回声用法:./nmap<港口范围>< IP-列表>< d || ^ h || B>中
    1号出口
科幻头(){
    加入-A1 -a2 -j 2 $ 2 $ 1 |阅读的同时IP端口
     做
        回声-n$ IP $端口
        OUT = $(NMAP -p$端口--script = HTTP-headers.nse$ IP| TAC | awk的-F:NR< = 13安培;&安培; /阿帕奇/ {打印$ 2;退出}')
        如果[$ OUT== *阿帕奇*];然后
            回声$ $ IP端口和GT;> right.txt
        其他
            回声$ $ IP端口和GT;> wrong.txt
        科幻
     DONE
}案例$ 3
  H)头;;
  D)的回波数据;;
  B)呼应既;;
  *)回声输入错误
       出口;;
ESAC

I wrote something like:

OUT=$( nmap -p "$port" --script=http-headers.nse "$ip"

for example the output is:

|http-headers: 
|   Server: Apache
|   Vary: Accept-Encoding
|   Content-Type: text/html; charset=utf-8
|   Date: Thu, 06 Feb 2014 07:31:33 GMT
|   Age: 25
|   Connection: close

but the length of my output is changeable. so I want something to search between lines in my output (better to use sed or awk) and check a condition. for example if it sees Apache from line 3 till line 8 then echo right

Edit:

my script:

#!/bin/bash

echo "Reading data - headers - both"

if [ $# -ne 3 ]; then
    echo "Usage: ./nmap <port-range> <ip-list> <d || h || b>"
    exit 1
fi

if [ $3 == h ]; then
    while read -r -u3 port; do
    while read -r -u4 ip; do


        echo -n "$ip $port: "
        OUT=$( nmap -p "$port" --script=http-headers.nse "$ip" |
        tail -n 13 | 
        awk -F: '{print $2; exit}')   in other lines
        [[ $OUT == *Apache* ]] && echo right || echo wrong 
    done 4< "$2"
    done 3< "$1"

elif [ $3 == d ]; then
    echo data
elif [ $3 == b ]; then 
    echo both
fi

I want to put my right result in file...for example:

cat right.txt
ip1  port1
ip2  port2

cat wrong.txt
ip1 port1
ip2 port2

解决方案

Here is the fix

#!/bin/bash

echo "Reading data - headers - both"

if [ $# -ne 3 ]; then
    echo "Usage: ./nmap <port-range> <ip-list> <d || h || b>"
    exit 1
fi

headers () {
    join -a1 -a2 -j 2 $2 $1 |while read ip port
     do
        echo -n "$ip $port:"
        OUT=$(nmap -p "$port" --script=http-headers.nse "$ip" | tac | awk -F: 'NR<=13&&/Apache/{print $2; exit}')   
        if [[ "$OUT" == *Apache* ]]; then
            echo $ip $port >> right.txt
        else
            echo $ip $port >> wrong.txt
        fi
     done
} 

case $3 in 
  "h") headers ;;
  "d") echo data;;
  "b") echo both;;
  "*") echo "wrong input"
       exit;;
esac

这篇关于从具体的线路输出和猫搜索到特定的行并重新搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆