对socks5代理进行检验

代理文本proxychains.txt格式

1 118.121.8.9 1080 SOCKS5

2 192.99.3.101 1080 SOCKS5

3 116.228.3.82 80 SOCKS5

4 45.56.108.26 16674 SOCKS5

----------------------------------------------------

# -*- coding:utf-8 -*-

import time

import requests

'''''

代理IP地址

'''

def getProxyIp():

proxy = []

inFile = open('proxychains.txt','r')

for line in inFile.readlines():

line = line.strip('\n')

IP= line.split("\t")

ip_temp = IP[0]+":"+IP[1]+":"+IP[2]

proxy.append(ip_temp)

return proxy

'''''

验证代理IP地址是否可用

'''

def validateIp(proxy):

url = "https://www.facebook.com"

headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '

'AppleWebKit/537.36 (KHTML,like Gecko) '

'Chrome/56.0.2924.87Safari/537.36'}

f = open("ip-socks5.txt","wb")

for i in range(0,len(proxy)):

try:

ip =proxy[i].split(":")

print ip

proxies = {'http':'socks5://'+ip[1]+":"+ip[2],'https':'socks5://'+ip[1]+":"+ip[2],}

url = 'https://www.facebook.com'

response = requests.get(url,proxies=proxies,timeout=5)

print(response.content)

f.write(ip+'\t') #proxy[i]

print ("successful")

time.sleep(2)

except Exception as e:

print("failed") # continue

f.close()

if __name__ == '__main__':

print "Running tests..."

proxy=getProxyIp()

validateIp(proxy)

  • 发表于:
  • 原文链接http://kuaibao.qq.com/s/20180408G0005L00?refer=cp_1026
  • 腾讯「云+社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 yunjia_community@tencent.com 删除。

扫码关注云+社区

领取腾讯云代金券