在 grep 中需要帮助 (BASH)

need help in grep (BASH)

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

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

第一步

base64不是加密,而是编码。如果你正在从事 Linux 或其他 Unix 变体,命令 base64、base64-encoder/decoder、 将被预先安装。如果没有,它将很容易地与您一起安装 OS-依赖包管理器。 那么请尝试执行:

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

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

第三步

现在我们要以IP:PORT的格式合并IP和PORT。 我们可以使用 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 <(command1) <(command2) 保存以创建临时文件。