加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

用perl获取可用的代理服务器地址

发布时间:2020-12-16 00:37:13 所属栏目:大数据 来源:网络整理
导读:对于网速慢,被墙的朋友,你们有福了,我现在把我经常获取可以的代理服务器地址的代码发出来 ? ? ? ########################################## ? ? #获取有效http代理服务器列表程序 ? ? #作者:yifangyou ? ? #创建时间:2011-03-27?17:14:00 ? ? #本程序实

对于网速慢,被墙的朋友,你们有福了,我现在把我经常获取可以的代理服务器地址的代码发出来

?

?

?

 
 
  1. ########################################## ?
  2. ?
  3. #获取有效http代理服务器列表程序 ?
  4. ?
  5. #作者:yifangyou ?
  6. ?
  7. #创建时间:2011-03-27?17:14:00 ?
  8. ?
  9. #本程序实现 ?
  10. ?
  11. #1.从代理网站获取代理服务器列表 ?
  12. ?
  13. #2.逐个检测代理服务器是否可用 ?
  14. ?
  15. ########################################## ?
  16. ?
  17. package?yifangyou; ?
  18. use?LWP::Simple; ?
  19. use?LWP::UserAgent; ?
  20. use?strict;? ?
  21. use?warnings; ?
  22. use?LWP::Simple?qw(?$ua?get?); ?
  23. #代理服务器ip和端口存放的地方 ?
  24. ?
  25. my?@proxys=(); ?
  26. #已经检测完的代理服务器ip和端口存放的地方 ?
  27. ?
  28. my?@checkedProxys=(); ?
  29. #已经检测完的代理服务器ip和端口存放的地方,我用的百度首页的图标 ?
  30. ?
  31. my?$stdUrl="http://www.baidu.com/img/baidu_sylogo1.gif";? ?
  32. #代理服务器列表页面的url,可以加多个页面 ?
  33. ?
  34. my?@urls=("http://www.5uproxy.net/http_fast.html");#,"http://www.5uproxy.net/http_anonymous.html","http://www.5uproxy.net/http_non_anonymous.html"); ?
  35. ?
  36. $ua->timeout(3);?#?3秒超时 ?
  37. ?
  38. $ua->agent("Mozilla/4.0?(compatible;?MSIE?7.0;?Windows?NT?5.1)");?#?模拟xp?ie7浏览器 ?
  39. ?
  40. #获取待验证的代理服务器列表 ?
  41. ?
  42. foreach?my?$url(@urls){ ?
  43. ????getProxyAddr($url); ?
  44. } ?
  45. #验证代理服务器列表 ?
  46. ?
  47. foreach?my?$proxyAddr(@proxys){ ?
  48. ????checkProxyAddr($stdUrl,$proxyAddr); ?
  49. } ?
  50. #输出所有结果 ?
  51. ?
  52. print?join(",",@checkedProxys)."n"; ?
  53. ?
  54. #获取待验证的代理服务器列表 ?
  55. ?
  56. sub?getProxyAddr ?
  57. { ?
  58. ??????my?$url=shift; ?
  59. ????my?$document?=?get($url); ?
  60. ????return?print?"cannot?get?$urln"?unless?defined?$document; ?
  61. ????my?@lines=split("n",$document); ?
  62. ????my?$i=0; ?
  63. ????my?@matches; ?
  64. ????for($i=0;$i<@lines;$i++){ ?
  65. ????????#获取ip ?
  66. ?
  67. ????????if(@matches=$lines[$i]=~/(d{1,3}.d{1,3})/i)?{ ?
  68. ????????????my?$ip=$matches[0]; ?
  69. ????????????#获取端口 ?
  70. ?
  71. ????????if(@matches=$lines[$i+1]=~/<td.*>(d{1,6})</td>/i)?{ ?
  72. ???????????my?$port=$matches[0]; ?
  73. ???????????push(@proxys,"$ip:$port"); ?
  74. ????????}? ?
  75. ??????} ?
  76. ????} ?
  77. } ?
  78. ?
  79. #验证代理服务器列表 ?
  80. ?
  81. sub?checkProxyAddr{ ?
  82. ????my?$url=shift; ?
  83. ????my?$proxyAddr=shift; ?
  84. ?? ?
  85. ??$ua->proxy(['http'],?"http://$proxyAddr");?#?设http代理服务器 ?
  86. ?
  87. ??my?@headcontent=head($url);?#取head比较快 ?
  88. ?
  89. ??if(scalar(@headcontent)==0){ ?
  90. #?????print?"Could?not?get?head?from?$proxyAddrn"; ?
  91. ?
  92. ??????return?-1;????????? ?
  93. ??}else{ ?
  94. ??????????print?"$proxyAddrn"; ?
  95. ??????????push(@checkedProxys,"$proxyAddr"); ?
  96. ??????????return?0; ?
  97. ??}???? ?
  98. #????my?$ua?=?new?LWP::UserAgent; ?
  99. ?
  100. #?$ua->timeout(3);?#?3秒超时 ?
  101. ?
  102. #?$ua->proxy(['http'],?"http://$proxyAddr");?#?设http代理服务器 ?
  103. ?
  104. #?$ua->agent("Mozilla/4.0?(compatible;?MSIE?7.0;?Windows?NT?5.1)");?#?模拟xp?ie7浏览器 ?
  105. ?
  106. #?my?$req?=?new?HTTP::Request->new(GET?=>?$url); ?
  107. ?
  108. #?my?$res?=?$ua->request($req); ?
  109. ?
  110. #?if?($res->is_success){ ?
  111. ?
  112. #?????????print?"$proxyAddrn"; ?
  113. ?
  114. #?????????push(@checkedProxys,"$proxyAddr"); ?
  115. ?
  116. #?????????return?0; ?
  117. ?
  118. #?}else?{ ?
  119. ?
  120. #?????print?"Could?not?get?head?from?$proxyAddrn"; ?
  121. ?
  122. #?????return?-1; ?
  123. ?
  124. #????} ?
  125. ?
  126. }?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读