惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - 你看起来真的很好吃

linux系统时间管理 安装历史docker版本 OCR文本提取+NER命名实体识别 测试 深度学习-激活函数 go——make和new的区别 go——GC垃圾回收机制 go——标识符的命名规范 go语言——数据类型 go语言——转义符 go开发环境安装 git使用 项目文档目录总结 鼠标连点器——python版 windows使用YOLOV5训练模型——搭建编译环境 logging模块进行格式化输出 笔记 Django admin 添加操作记录 facenet + fiass 实现人脸识别
高匿名动态IP代理获取
你看起来真的很好吃 · 2023-11-13 · via 博客园 - 你看起来真的很好吃
# -*-coding:utf-8-*-
# IP proxy
import json
import time

import requests
from threading import Lock

class IpProxy(object):
_local = Lock()
_instance = None
# 代理IP过期时间, IP有效时长为60秒, 代理IP
effective_duration = 60
expire_time_stamp = 0
proxy_ip = []

# 青果网络高匿名代理IP获取参数 api_url:https://www.qg.net/doc/api/3_117_210/1846.html
ip_proxy_host = "http://share.proxy.qg.net/get"
# 密码
pwd = "xxx"
# 公共参数,产品唯一标识。
key = "xxxx"
# 指定地区提取。如果用的是省代码,可以提取到这个省下任意市的IP 。
area = "410000"
# 排除指定地区。如果用的是省代码,则不会提取到这个省的IP 。
area_ex = ""
# 按运营商提取。
# 0: 不筛选
# 1: 电信
# 2: 移动
# 3: 联通
isp = 0
# 提取个数,默认为1。
num = 1
# 去重提取,默认为false。如果为true则不会提取到已经在使用的IP资源。
distinct = False
# 选择资源池提取。
# 1: 普通池,默认
# 2: 企业池
pool = 1

def __new__(cls, *args, **kwargs):
if not cls._instance:
with cls._local:
if not cls._instance:
cls._instance = super(IpProxy, cls).__new__(cls, *args, **kwargs)
return cls._instance

def get_proxy_ip(self):
u"""获取代理IP"""
# 如果代理IP未过期
if self.expire_time_stamp > int(time.time()):
return True, self.proxy_ip

params = {}
if self.key:
params["key"] = self.key
if self.area:
params["area"] = self.area
if self.area_ex:
params["area_ex"] = self.area_ex
if self.isp:
params["isp"] = self.isp
if self.num:
params["num"] = self.num
if self.distinct:
params["distinct"] = self.distinct
if self.pool:
params["pool"] = self.pool

retry_count = 3
cur_num = 1
while cur_num <= retry_count:
re = requests.get(self.ip_proxy_host, params=params)
print(re.text)
if str(re.status_code).startswith("20"):
data_json = json.loads(re.text)
if data_json["code"] == "SUCCESS":
for item in data_json["data"]:
self.proxy_ip.append(item["server"])
print(item["server"])
self.expire_time_stamp = int(time.time()) + 60
return True, self.proxy_ip
cur_num += 1
return False, []

if __name__ == "__main__":
success_count = 0
fail_count = 0

for item in range(1000):
ip_proxy = IpProxy()
is_true, proxy_ip_list = ip_proxy.get_proxy_ip()
print(proxy_ip_list)

# if not is_true:
# fail_count += 1
# continue
#
# user_name = ip_proxy.key
# pwd = ip_proxy.pwd
# proxy_ip = proxy_ip_list[0]
#
# # 发送请求
# url = "http://httpbin.org/get"
# proxies = {
# "http": "http://%s:%s@%s" % (user_name, pwd, proxy_ip)
# # "https": "113.229.3.172:55046"
# }
# re = requests.get(url=url, proxies=proxies)
# if str(re.status_code).startswith("20"):
# data = json.loads(re.text)
# print("success, origin:%s" % data["origin"])
# success_count += 1
# else:
# fail_count += 1

print("success_count: %s" % success_count)
print("fail_count: %s" % fail_count)