【问题标题】:need help in grep (BASH)在 grep (BASH) 中需要帮助
【发布时间】:2021-04-17 19:32:01
【问题描述】:

我尝试制作一个工具来获取代理列表,并且您已经为我使用的其中一个免费代理网站下载了索引:

wget http://free-proxy.cz/en/proxylist/country/all/https/ping/all

并输出类似的东西:

<script type="text/javascript">document.write(Base64.decode("MTg1LjExNC4xMzcuMTQ="))</script></td><td style=""><span class="fport" style=''>12195</span></td><td><small>HTTPS</small></td><td class="left"><div style="padding-left:2px"><img src="/flags/blank.gif" class="flag flag-ua" alt="Ukraine" /> <a href="/en/proxylist/country/UA/all/ping/all">Ukraine</a></div></td><td class="small"><small></small></td><td class="small"><small></small></td><td class="small"><small>High anonymity</small></td><td> <i class="icon-black icon-question-sign"></i></td><td><small>2.4%</small><div class="progress"><div class="fill" style="width:4%;background-color:red;"></div></div></td><td><div style="padding-left:5px"><small>649 ms</small> <div class="progress"><div class="fill" style="width:94%;background-color:#A5DA74;;"></div></div></div></td><td><small>8 hours ago</small></td></tr><tr><td style="text-align:center" class="left"><script type="text/javascript">document.write(Base64.decode("MTYxLjk3LjEzOC4yMzg="))</script></td><td style=""><span class="fport" style=''>3128</span></td><td>

你可以看到IP是base64加密的,端口是正常的

我先尝试 grep base64 代码,这是可行的 ↓

echo (outputs) | grep -Eo '("[A-Za-z0-9]{12,30}[=]{0,2}")' | cut -d '"' -f2

我尝试使用此代码获取端口 ↓

echo (output) | grep -Eo "(class=\"fport\" style=''>[0-9]{1,9})"  | cut -d '>' -f2

我怎样才能把它混合成那样

(base64 code):(port)

然后我想解密 base64 代码并使它看起来像:

IP:PORT

【问题讨论】:

  • 要求“快速回答”是不受欢迎的——不仅在这里,而且在一般情况下;见catb.org/~esr/faqs/smart-questions.html#urgent。如果您花时间想出一个准确描述您的具体问题的标题,您还将获得更好的响应(更多、更高质量的答案;更少的反对票)。
  • ...一般来说,这里写问题和答案的重点不仅仅是帮助第一个提出问题的人,而是帮助其他所有遇到同样问题的人未来。这意味着双方都应该花时间专注于写出最好的问题和最好的答案,以最好地帮助其他人从问题和回答中学习。

标签: bash shell command-line grep


【解决方案1】:

第一步

base64 不是加密,而是编码。如果你正在工作 Linux 或其他 Unix 变体,命令 base64,base64-encoder/decoder, 将被预装。如果没有,它将很容易与您的 依赖于操作系统的包管理器。 那么请尝试执行:

base64 -d <<< "MTg1LjExNC4xMzcuMTQ="

它会输出:

185.114.137.14

第二步

然后我们可以将 base64 解码器与您的命令管道相结合。 问题是 base64 编码忽略换行,我们需要处理 逐行流水线的结果。假设变量$output 保存wget 命令的输出,请尝试:

while IFS= read -r line; do
    base64 -d <<< "$line"
    echo
done < <(echo "$output" | grep -Eo '("[A-Za-z0-9]{12,30}[=]{0,2}")' | cut -d '"' -f2)

它将打印如下内容:

185.114.137.14
161.97.138.238

&lt;(command) 表示法是一个进程替换和输出 echo .. grep .. cut 管道通过标准输入馈送到while 循环 while 循环逐行处理base64编码的字符串。

第三步

现在我们想以IP:PORT 的格式合并 IP 和端口。 我们可以使用paste 命令。最终脚本将是:

paste -d ":" <(
while IFS= read -r line; do
    base64 -d <<< "$line"
    echo
done < <(echo "$output" | grep -Eo '("[A-Za-z0-9]{12,30}[=]{0,2}")' | cut -d '"' -f2)
) \
<(echo "$output" | grep -Eo "(class=\"fport\" style=''>[0-9]{1,9})"  | cut -d '>' -f2)

输出:

185.114.137.14:12195
161.97.138.238:3128

paste 命令将文件名作为参数。这里我们利用 再次以如下方式替换进程:paste &lt;(command1) &lt;(command2) 保存以创建临时文件。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-22
    • 1970-01-01
    • 2016-11-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多