验证最新可用代理 For http://www.5uproxy.net 多线程版

本文介绍了一个使用Python编写的多线程代理验证器,该验证器能够从指定网站抓取代理列表,并验证这些代理的有效性和响应速度。验证后的有效代理会按照响应时间排序并保存到本地文件中。




# coding:gbk
# 验证最新可用代理 For http://www.5uproxy.net 多线程版
#  2010.12.05

import sys
reload(sys)
sys.setdefaultencoding('gbk')


import urllib
import urllib2
from urllib2 import URLError, HTTPError

DEBUG = True

#html页面下载函数
def getHtml(url,post_data=None,cookie=None):
        """Fetch the target html
        url - URL to fetch
        post_data - POST Entity
        cookie - Cookie Header
        """
        if DEBUG:
            print "getHtml: ",url

        result =''
        
        try:
            #create a request
            request = urllib2.Request(url)

            #change User-Agent
            request.add_header('User-Agent','Mozilla/5.0')
            
            #change Referrer
            request.add_header('Referrer',url)
            
            #if has cookie,add cookie header
            if cookie:
               request.add_header('Cookie',cookie)

            #create a opener
            opener = urllib2.build_opener()            
           
            #if has post entity
            if post_data:
                #encode post data
                post_data = urllib.urlencode(post_data)
                
                response = opener.open(request,post_data)
            else:
                response = opener.open(request)
            
            result = response.read()
                
            response.close()

            #no content,don't save
            if not result or len(result)==0:
                return ''
            
            return  result
        except HTTPError, e:
            if DEBUG:
                print 'Error retrieving data:',e
                print 'Server error document follows:\n'
                #print e.read()
            return ''
        except URLError, e:
            if hasattr(e, 'reason'):
                if DEBUG:
                    print 'Failed to reach a server.'
                    print 'Reason: ', e.reason
                return ''
            elif hasattr(e, 'code'):
                if DEBUG:
                    print 'The server couldn\'t fulfill the request.'
                    print 'Error code: ', e.code
                return ''
        except Exception, e:
            if DEBUG:
                print e
            return ''
        

#需要验证的代理列表
proxy_urls = []
proxy_urls.append({'url':'http://www.5uproxy.net/http_fast.html','type':'http_fast'})
proxy_urls.append({'url':'http://www.5uproxy.net/http_anonymous.html','type':'http_anonymous'})
proxy_urls.append({'url':'http://www.5uproxy.net/http_non_anonymous.html','type':'http_transparent'})
proxy_urls.append({'url':'http://www.5uproxy.net/socks5.html','type':'socks5'})


import re
import socket
import time
import threading

result =[]


#线程同步锁
lock = threading.Lock() 

def synchronous(f):
    def call(*args, **kwargs):
        lock.acquire()
        try:
            return f(*args, **kwargs)
        finally:
            lock.release()
    return call



#先获取所有待验证的代理
proxies = []

for proxy_url in proxy_urls:
    html = getHtml(proxy_url['url'])
    
    #正则匹配获取每一代理
    rs = re.compile(r'''<tr .*?>[\s\S]*?<td .*?>\d+?</td>[\s\S]*?<td>(\S+?)</td>[\s\S]*?<td .*?>(\S+?)</td>[\s\S]*?<td .*?>(\S+?)</td>[\s\S]*?</tr>''',re.DOTALL).findall(html)
    
    for r in rs:
        proxy = {}
        
        #代理域名
        proxy['domain'] = r[0]
        #代理端口
        proxy['port'] = r[1]
        #代理国家
        proxy['state'] = r[2]
        #代理类型
        proxy['type'] = proxy_url['type']
        #响应时间
        proxy['time'] = 0
        
        if not (proxy in proxies):
            proxies.append(proxy)



#获取一个待验证代理
@synchronous
def getproxy():
    global proxies
    if len(proxies)>0:
        return proxies.pop()
    else:
        return ''


    
#保存验证结果
@synchronous
def saveresult(proxy):
    global result
    
    if not(proxy in result):
        result.append(proxy)


#线程函数
def verify():
    
    while 1:
        proxy = getproxy()
        #所有代理均已验证完毕
        if len(proxy)==0:
            return
        
        print "正在验证:%s,%s" % (proxy['domain'],proxy['port'])
        
        #验证代理的可用性
        #创建一个TCP连接套接字
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        #设置10超时
        sock.settimeout(10)
        try:
            start = time.clock()
            
            #连接代理服务器
            sock.connect((proxy['domain'], int(proxy['port'])))
            proxy['time'] = int((time.clock() - start) * 1000) 
            sock.close()
            
            saveresult(proxy)
            print "%s,%s 验证通过,响应时间:%d ms." % (proxy['domain'],proxy['port'],proxy['time'])
        except Exception, e:
            if DEBUG:
                print e
            
            print "%s,%s 验证失败." % (proxy['domain'],proxy['port'])




#init thread_pool 
thread_pool = []

for i in range(20): 
    th = threading.Thread(target=verify,args=()) ; 
    thread_pool.append(th)

# start threads one by one         
for thread in thread_pool: 
    thread.start()

#collect all threads 
for thread in thread_pool: 
    threading.Thread.join(thread)


#结果按响应时间从小到大排序

result.sort(lambda x,y: cmp(x['time'], y['time']))  

fname = 'proxy_'+ time.strftime('%Y-%m-%d-%H-%M-%S',time.localtime(time.time())) +'.txt'
file = open(fname,'w')

print "验证结果如下:"
for item in result:
    str = '%s,%s,%s,%s,%d' % (item['type'],item['domain'],item['port'],item['state'],item['time'])
    print str
    file.write(str+'\n')
    
file.close()

print "所有代理已验证完毕,共计%d个验证通过。验证通过的代理已存入%s" % (len(result),fname)
    
    
     


检测到 URI Encoded 响应.Write Web Shell Command or ASP Injection_111.14.219.164_soar 关联分析规则:攻击成功告警详情同步 威胁信息:检测到 URI Encoded 响应.Write Web Shell Command or ASP Injection 源地址:111.14.219.164 目的地址:dmz.16.27.32 国家:未知 城市:济南市 威胁特征:特征1:"Response.Write(" 请求信息: GET /eportal/uiFramework/huilan-jquery-ui/js/huilan-jquery-ui.js?self=Response.Write(8-9999108099999)Response.Write(8-9999108099999)&skin=default&random=15634 HTTP/1.1 Host: www.sdrcu.com User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E; rv 11.0) like Gecko Accept: / Accept-Encoding: gzip,deflate Cookie: JSESSIONID=14A17910D75D77483452D1799DFD73D3;BIGipServerpool_oportal_ap_7088=!xoge/nyTnrRWZS8TF7YXYUJzE1lDsf7jgbnzZXvg2d/v51Au28RaGwclF9hzwVhpNKb5uOddB8+wrw==;BIGipServerpool_oportal_web_7099=!chiGSj+Py5cpWUZZvUwc8o53CerdpWa67Vih9IQqElG/SD0RXOl0t3y5cuzQFMimyBjtfKmLV8zF6g==; Connection: Keep-alive Via: 1.1 ID-0016035512643552 uproxy-3 X-Forwarded-For: 111.14.219.164 返回信息: HTTP/1.1 200 Date: Mon, 10 Mar 2025 13:19:36 GMT Content-Type: application/x-javascript;charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Vary: Accept-Encoding ETag: W/"170617-1713850962000" Last-Modified: Tue, 23 Apr 2024 05:42:42 GMT X-Frame-Options: SAMEORIGIN Content-Encoding: gzip .....items : [ 'Source', '-', 'DocProps', 'Print', '-' ] ......}, ......{ .......name : 'clipboard', .......items : [ 'PasteText', 'PasteFromWord', '-', .........'Undo', 'Redo', '-' ] ......}, ......{ .......name : 'editing', .......items : [ 'Find', 'Replace', '-', 'SelectAll' ] ......}, ......{ .......name : 'insert', .......items : [ 'Image', 'Flash', 'Table', .........'HorizontalRule', '-' ] ......}, ......// '/', ......{ .......name : 'basicstyles', .......items : [ 'Bold', 'Italic', 'Underline', 'Strike', .........'-', 'RemoveFormat' ] ......}, ......{ .......name : 'paragraph', .......items : [ 'JustifyLeft', 'JustifyCenter', .........'JustifyRight', 'JustifyBlock', '-' ] ......}, { .......name : 'links', .......items : [ 'Link', 'Unlink', '-' ] ......}, ......// 'textindent','textoutdent','textIndentAll','delAllFirstSpaces','delEmptyP','changetext' ......// '/', ......{ .......name : 'styles', .......items : [ 'Font', 'FontSize', '-' ] ......}, { .......name : 'colors', .......items : [ 'TextColor', 'BGColor', '-' ] ......}, { .......name : 'tools', .......items : [ 'ShowBlocks' ] ......} ] ...}); .return ckeditor; } function getMyCkEditor(id, array, has 这是攻击吗?
03-12
curl -v https://epass.icbc.com.cn/regist/regist_index.jsp * Trying 211.95.81.142... * TCP_NODELAY set * Connected to epass.icbc.com.cn (211.95.81.142) port 443 (#0) * schannel: SSL/TLS connection with epass.icbc.com.cn port 443 (step 1/3) * schannel: checking server certificate revocation * schannel: sending initial handshake data: sending 182 bytes... * schannel: sent initial handshake data: sent 182 bytes * schannel: SSL/TLS connection with epass.icbc.com.cn port 443 (step 2/3) * schannel: failed to receive handshake, need more data * schannel: SSL/TLS connection with epass.icbc.com.cn port 443 (step 2/3) * schannel: encrypted data got 4096 * schannel: encrypted data buffer: offset 4096 length 4096 * schannel: encrypted data length: 8 * schannel: encrypted data buffer: offset 8 length 4096 * schannel: received incomplete message, need more data * schannel: SSL/TLS connection with epass.icbc.com.cn port 443 (step 2/3) * schannel: encrypted data got 339 * schannel: encrypted data buffer: offset 347 length 4096 * schannel: sending next handshake data: sending 126 bytes... * schannel: SSL/TLS connection with epass.icbc.com.cn port 443 (step 2/3) * schannel: encrypted data got 51 * schannel: encrypted data buffer: offset 51 length 4096 * schannel: SSL/TLS handshake complete * schannel: SSL/TLS connection with epass.icbc.com.cn port 443 (step 3/3) * schannel: stored credential handle in session cache > GET /regist/regist_index.jsp HTTP/1.1 > Host: epass.icbc.com.cn > User-Agent: curl/7.55.1 > Accept: */* > * schannel: client wants to read 102400 bytes * schannel: encdata_buffer resized 103424 * schannel: encrypted data buffer: offset 0 length 103424 * schannel: encrypted data got 688 * schannel: encrypted data buffer: offset 688 length 103424 * schannel: decrypted data length: 659 * schannel: decrypted data added: 659 * schannel: decrypted data cached: offset 659 length 102400 * schannel: encrypted data buffer: offset 0 length 103424 * schannel: decrypted data buffer: offset 659 length 102400 * schannel: schannel_recv cleanup * schannel: decrypted data returned 659 * schannel: decrypted data buffer: offset 0 length 102400 < HTTP/1.1 500 < Server: BWS < Date: Mon, 21 Jul 2025 03:32:26 GMT < Content-Type: application/json < Transfer-Encoding: chunked < Content-Disposition: inline;filename=f.txt < Set-Cookie: JSESSIONID=B4EAC69C27D9AE1668A3CA99EADF0C55; Path=/; Secure; HttpOnly < Set-Cookie: CK_ISN_EPASS_EPASS-FUSION-4_PAAS=epass-app-w-6-wgq-654dbbbdbd-hwsfb-84|aH20z|aH20z; path=/ < Set-Cookie: CK_ISW_EPASS_WEB-HW-HTTPS-9_PAAS=epass-web-2-wgq-6cbbdfb8bd-slxkz-10|aH20z|aH20z; path=/ < Connection: Keep-alive < Via: 1.1 ID-7203207600110724 uproxy-31 < {"timestamp":"2025-07-21T03:32:26.827+00:00","status":500,"error":"Internal Server Error","path":"/regist/regist_index.jsp"}* Connection #0 to host epass.icbc.com.cn left intact 请问为什么响应码是500
07-22
>> 本文件内容为 https://fmkp.jnrcb.com.cn/api-yxy-out/api/middleware/app/realNameAuthentication/authentication 的请求抓包详情,供您分析和定位问题。 1. 请求内容 Request: POST /api-yxy-out/api/middleware/app/realNameAuthentication/authentication HTTP/1.1 Host: fmkp.jnrcb.com.cn Connection: keep-alive Content-Length: 392 Sign-Version: v2 X-Token: 9HYRC+SGoMc1NB8rab1q2g== content-type: application/json f3qq1: b0WqWs7AMNEozrkjtpU5oR5mjYMSwZTOM7MarW_goTFFK9UjAQ_lFWgtCA18K6ciwE5UC_AHb9b_9xpMz2Jg1v8m53MAHlaFd5hVOi9l40vzPK78FSN.R4Ck37Ah6byeDU0LaKHzQE8MjOONgKcSIlVQCqTmZyUVmV17YcMEeYy667B66OEl52Z219x6ft59OOLt3coMUTGXcUeqif9wvHEe9mkLEpz3.cE_V.JUEJ.6bj5wIeskbBUTYgsEFXGz99qyYakSzPOKYQozE9hzKnnf5BZISC0_ZauOKTBXGLW3sO5616OPRUcXQ1Cbl_7CqH6qb75PpoLK2T5.Rs26XxoJqvaTxkbL7tldj_tzu_dzpRgJbJmF1bipZwbZbU91ox2mIpbBaLIhHyM03c9krYdfBqVnrEXa8rIBfn3tJhec.NiX6Lbof_JRrh29.LJT09tsa3u1kkwdwyCYBIGkMt1OCvseDHW0iaSc53pFkQJSbOfw3WDTmzB74BoXGWJV5E5QfSwALFaoUBttAabwLPiRO_6HR1mzpy5uL50TsAywIEO2SadOkkv3veuKcygaMfzsQUOoQTwTO5DSckAT2Gi.wZnCv5LS3V5tTSTvMWaKcQRWQy77nV_BUvkZHs6PnPq7.iaXCL6fDVGiPwsjWozjw.KaHm7zBPkPKj2aCluZECMNwgfTqTSRUmddZJg1xq4dSzkLSAC8pph6Et9IiMKLg signature: jWNWV9V8o/XMjfY3QajX6y3Jj2KXJSaI68jUnOywMtI= timestamp: 1741363056936 nonce: 691042 Accept-Encoding: gzip,compress,br,deflate User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 18_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.56(0x18003836) NetType/WIFI Language/zh_CN Referer: https://servicewechat.com/wxc92d4a929315475b/216/page-frame.html f3qq1=b0JmW_9YJ06lSNv1wFhyWTDoZRy_YoI9bgDN2gpx7N2Om1oU3H6Cl7.pUOd8t1K_Sq2sEBZ8Zm0m5Hrwt75X9wmPJXKHsmonwcrK0tHaiSdn6ARtQYpViPq36zSSzajW5r0eTAkn4G.9c6k6fS7KnYcyEdldlCuMcdaiufMJI8D.y37O9nmUbtibkj70X1mnIj8C6_2gxVe55omx6BfticbP6bASygN9FLD5MFXvThar1wYel.C1c8E2rw.WC809Y914eQpll2RnIdcg0ilhIZLI_aBg1zPjz1ocvTr9CLqEOyc6.IMClO88_GCFQKVBUxFXLjkTIlKDqkCIA7LZEFzQVUIiTYRoawJttlAXjKfMErS1TqvnC0uH8oPpMLNu8O 2. 响应内容 Response: HTTP/1.1 200 Server: ****** Content-Type: application/json Transfer-Encoding: chunked Date: Fri, 07 Mar 2025 15:57:37 GMT Set-Cookie: BIGipServerpool_WAF_QMYXCX_ipv4_29292_to_9292=!js6HDXqFdZyin39UpAVs/fNUMmq28A/kUTQrnbiU8OiE4aKj2GRwUtrtA2bjeSWRxmgf6cbiFxDt; path=/; Httponly; Secure bavte: b0Gm2T9I6f.VzLxg2TJzR92So9DxQgvgxBGp9dYLBiN2xIl1u9qhtANSSEgeIwaFj7npQKJyzuvs2jPjnFNdtO1a Content-Encoding: gzip Set-Cookie: BIGipServerpool_ruishu_FMKP_ipv4_19292_to_9292=1376943882.23627.0000; path=/; Httponly; Secure Connection: Keep-alive Via: 1.1 ID-1716635744553530 uproxy-5 bavte=b0.KJzCQtcCm5jcT83TJNyYIgSTqkoEcfa3leCK0LjFSkh3Y8rEI2HEdByr4KeRQceERoeyXLhhjvAEj69qbifXAVIbjhG2jITMjLFUwhjiicbEvsKDKR5GzT8CoDH09erMhstMo3LBqTHNvdk83hgLYW6qIvTcDq0Q6F0P_UylQE 请帮我解密
03-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值