首页 > 解决方案 > 从 .html 文件中获取 IP

问题描述

他们是一个带有 socks4 在线代理的网站,我在代理链程序中使用它。我没有手动输入新的 IP,而是试图自动化这个过程。我使用 wget 将其转换为我的主目录中的 .html 文件,这是我 cat 文件时的一些输出:

</font></a></td><td colspan=1><font class=spy1>111.230.138.177</font> <font class=spy14>(Shenzhen Tencent Computer Systems Company Limited)</font></td><td colspan=1><font class=spy1>6.531</font></td><td colspan=1><TABLE width='13' height='8' CELLPADDING=0 CELLSPACING=0><TR  BGCOLOR=blue><TD  width=1></TD></TR></TABLE></td><td colspan=1><font class=spy1><acronym title='311 of 436 - last check status=OK'>71% <font class=spy1>(311)</font> <font class=spy5>-</font></acronym></font></td><td colspan=1><font class=spy1><font class=spy14>05-jun-2020</font> 23:06 <font class=spy5>(4 mins ago)</font></font></td></tr><tr class=spy1x onmouseover="this.style.background='#002424'" onmouseout="this.style.background='#19373A'"><td colspan=1><font class=spy14>139.99.104.233<script type="text/javascript">document.write("<font class=spy2>:<\/font>"+(a1j0e5^q7p6)+(m3f6f6^r8c3)+(a1j0e5^q7p6)+(t0b2s9^y5m3)+(w3c3m3^z6j0))</script></font></td><td colspan=1>SOCKS5</td><td colspan=1><a href='/en/anonymous-proxy-list/'><font class=spy1>HIA</font></a></td><td colspan=1><a href='/free-proxy-list/CA/'><font class=spy14>Canada</

如您所见,IP 通常后跟一个 spy[0-19]> 。我尝试使用以下代码使用 awk 解析出实际 IP:

awk '/^spy/{FS=">";  print $2 } file-name.html

这是有问题的,因为它们会在 IP 之后出现一堆其他的东西,而且我猜锚点在一行的开头起作用?无论如何,我想知道是否有人可以给我任何关于如何使用 awk 解析 IP 地址的想法。我刚开始学习awk,很抱歉这个菜鸟问题。谢谢

标签: htmllinuxawktext-parsingstreamline

解决方案


这里已经提供了解决方案,我宁愿为使用实用程序的未来读者提供不同的解决方案。

egrep -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' file.html

推荐阅读