查找HTTP代理

http://letus.cc/archives/6

有时候需要测试某些IP是否提供了HTTP代理功能。于是写了如下代码,对192.168.x.x这个IP段进行扫描测试

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding:utf-8 -*- 
import socket
import threading
import Queue
 
timeout = 2   
socket.setdefaulttimeout(timeout)
threadnum = 256
ProxyPorts = [ 80 , 1080 , 3128 , 8080 , 8081 ]
 
 
reqcontent = "GET / HTTP/1.1\r\n" + \
              "Host: ip.cn\r\n" + \
              "Accept: */*\r\n" + \
              "User-Agent: curl/7.35.0curl/7.35.0\r\n\r\n"
 
def about():
     print "####################################################"
     print "find proxy"
     print "http://letus.cc/"
     print "####################################################"
 
class ipQueueCrawler(threading.Thread):
     def __init__( self , ipQueue):
         threading.Thread.__init__( self )
         self .ipQueue = ipQueue
 
     def run( self ): #Overwrite run() method, put what you want the thread do here
         while not self .ipQueue.empty():
             CurIp = self .ipQueue.get()
             print "left:" + str ( self .ipQueue.qsize()) + '\r' ,
             for ProxyPort in ProxyPorts:
                 try :
                     s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                     s.connect((CurIp,ProxyPort))
                     s.sendall(reqcontent)
                     data = s.recv( 500 )
                     if "IP:" + CurIp in data:
                         print CurIp + ":" + str (ProxyPort)
                     else :
                         pass
                         #print self.proxyIP + ":" + str(self.proxyPort) + ":No"
                     s.close()
                 except :
                     pass
                     #print self.proxyIP + ":" + str(self.proxyPort) + ":Except"
 
if __name__ = = '__main__' :
     about()
     ipQueue = Queue.Queue(maxsize = 256 * 256 + 1 )
     ipPrefix = "192.168."
     for ipMid in range ( 0 , 256 ):
         for ipLast in range ( 1 , 256 ):
             ipQueue.put(ipPrefix + str (ipMid) + "." + str (ipLast))
     
                                         
 
     for i in range ( 0 ,threadnum):
         ipQueueCrawler(ipQueue).start()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值