批量获取及验证HTTP代理的Python脚本

作者:mdxy-dxy 时间:2023-11-19 12:10:34 

HTTP暴力破解、撞库,有一些惯用的技巧,比如:

1. 在扫号人人网时,我遇到单个账号错误两次,强制要求输入验证码,而对方并未实施IP策略。

我采用维护10万(用户名,密码) 队列的方式来绕过验证码。具体的做法是,当某个用户名、密码组合遇到需要验证码,就把该破解序列挂起,放到队列尾部等待下次测试,继续破解其他账号密码。

这样就可以保证2/3的时间都在进行正常破解和扫号。

2. 在破解美团网某系统账号时,我遇到了单个IP访问有一定限制,请求频率不可过快。于是我挂了72个 HTTP代理来解决这个问题。 看似每个IP的请求都正常,但其实从整个程序上看,效率还是挺可观的。

本篇我发出自己抓HTTP的脚本片段,其实只有几行。匿名代理是从这里抓取的:http://www.xici.net.co/nn/

首先获取代理列表 :


from bs4 import BeautifulSoup
import urllib2

of = open('proxy.txt' , 'w')

for page in range(1, 160):
 html_doc = urllib2.urlopen('http://www.xici.net.co/nn/' + str(page) ).read()
 soup = BeautifulSoup(html_doc)
 trs = soup.find('table', id='ip_list').find_all('tr')
 for tr in trs[1:]:
   tds = tr.find_all('td')
   ip = tds[1].text.strip()
   port = tds[2].text.strip()
   protocol = tds[5].text.strip()
   if protocol == 'HTTP' or protocol == 'HTTPS':
     of.write('%s=%s:%s\n' % (protocol, ip, port) )
     print '%s=%s:%s' % (protocol, ip, port)

of.close()

接着验证代理是否可用,因为我是用于破解美团网系统的账号,因此用了美团的页面标记:


#encoding=gbk
import httplib
import time
import urllib
import threading

inFile = open('proxy.txt', 'r')
outFile = open('available.txt', 'w')

lock = threading.Lock()

def test():
 while True:
   lock.acquire()
   line = inFile.readline().strip()
   lock.release()
   if len(line) == 0: break
   protocol, proxy = line.split('=')
   headers = {'Content-Type': 'application/x-www-form-urlencoded',
     'Cookie': ''}
   try:
     conn = httplib.HTTPConnection(proxy, timeout=3.0)
     conn.request(method='POST', url='http://e.meituan.com/m/account/login', body='login=ttttttttttttttttttttttttttttttttttttt&password=bb&remember_username=1&auto_login=1', headers=headers )
     res = conn.getresponse()
     ret_headers = str( res.getheaders() )
     html_doc = res.read().decode('utf-8')
     print html_doc.encode('gbk')
     if ret_headers.find(u'/m/account/login/') > 0:
       lock.acquire()
       print 'add proxy', proxy
       outFile.write(proxy + '\n')
       lock.release()
     else:
       print '.',
   except Exception, e:
     print e

all_thread = []
for i in range(50):
 t = threading.Thread(target=test)
 all_thread.append(t)
 t.start()

for t in all_thread:
 t.join()

inFile.close()
outFile.close()


标签:验证,HTTP代理,Python脚本
0
投稿

猜你喜欢

  • 详解OpenCV图像的概念和基本操作

    2021-07-22 02:05:30
  • 详解python中的线程

    2021-11-19 18:30:35
  • python 同时读取多个文件的例子

    2022-06-27 03:56:50
  • python计算机视觉实现全景图像拼接示例

    2021-02-12 09:48:05
  • OpenCV哈里斯角检测|Harris Corner理论实践

    2021-03-22 02:06:10
  • 浅论网站用户粘性的提高和增强

    2008-05-15 07:14:00
  • 一文详解Golang中的切片数据类型

    2024-02-12 18:04:19
  • FSO无效的过程调用或参数问题

    2010-03-25 21:49:00
  • Python OpenCV实现识别信用卡号教程详解

    2021-08-12 03:50:27
  • MySQL中Like概念及用法讲解

    2024-01-21 01:12:07
  • asp实现本周的一周时间列表的代码

    2011-04-06 10:45:00
  • Python split() 函数拆分字符串将字符串转化为列的方法

    2022-02-12 00:14:19
  • 浅谈python中拼接路径os.path.join斜杠的问题

    2023-08-21 23:41:23
  • 通过实例了解JS 连续赋值

    2024-05-02 16:15:14
  • python中的反斜杠问题深入讲解

    2023-04-20 14:08:36
  • python应用文件读取与登录注册功能

    2023-04-17 17:04:03
  • php时间戳格式化显示友好的时间函数分享

    2024-05-11 09:22:42
  • Golang 发送http请求时设置header的实现

    2024-05-08 10:45:45
  • Python 实现opencv所使用的图片格式与 base64 转换

    2021-02-28 11:59:09
  • 深入理解Django的信号机制

    2023-01-20 10:19:58
  • asp之家 网络编程 m.aspxhome.com