【问题标题】:creating 2 variables from a multiple pattern grep从多个模式 grep 创建 2 个变量
【发布时间】:2012-11-12 17:00:42
【问题描述】:

我正在尝试创建一个概念验证 bash 脚本来使用 ngrep 扫描网络,找到合适的 cookie,然后将它们放入一个变量中。

cook=`ngrep -s 1000 -l -q -d eth1 "Cookie:" tcp and port 80 |
  grep -m 1 -Po '(?<=user=)[^;]+'` 

cook2=`ngrep -s 1000 -l -q -d eth1 "Cookie:" tcp and port 80 |
  grep -m 1 -Po '(?<=ab=)[^;]+'` 

如何从 ONE 数据包中存储 cookie 和 cookie2 而不必进行两次 ngrep?

【问题讨论】:

    标签: variables grep ngrep


    【解决方案1】:

    假设字符串是这种形式

    Cookie: foo=111; bar=222; baz=333
    

    您可以获取该字符串,因为它是有效的 Bash 代码。示例

    ngrep -s 1000 -l -q -d eth1 'Cookie:' tcp and port 80 | cut -d: -f2- > v.sh
    . v.sh
    rm v.sh
    cook="$user"
    cook2="$ab"
    

    【讨论】:

      猜你喜欢
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 1970-01-01
      • 2021-09-13
      相关资源
      最近更新 更多