# !/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Time: 2023/5/10 20:42
Author: Zhou Xu
Version: 1.0
Maintain By:
"""
import random
import requests
import threading
import time
my_headers = [
"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/537.75.14",
"Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0)",
'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11',
'Opera/9.25 (Windows NT 5.1; U; en)',
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)',
'Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko) (Kubuntu)',
'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.12) Gecko/20070731 Ubuntu/dapper-security Firefox/1.5.0.12',
'Lynx/2.8.5rel.1 libwww-FM/2.14 SSL-MM/1.4.1 GNUTLS/1.2.9',
"Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.7 (KHTML, like Gecko) Ubuntu/11.04 Chromium/16.0.912.77 Chrome/16.0.912.77 Safari/535.7",
"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:10.0) Gecko/20100101 Firefox/10.0 ",
"Mozilla/4.0 (compatible; MSIE 9.0; Windows NT 6.1; 125LA; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)"
]
url = "http://node.kg.qq.com/cgi/fcgi-bin/fcg_play_common_count?shareid=5TydovH5lAwg9Hx8&ptime=20&outCharset=utf-8&from=1&nocache=" + str(
int(round(time.time() * 1000))) + "&format=json&g_tk=5281&g_tk_openkey=5281"
header = {"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": random.choice(my_headers),
"Cache-Control": "no-cache",
"Host": "node.kg.qq.com",
"Accept": "*/*",
"Accept-Language": "zh-cn",
"Cookie": "euin_cookie=5E32280DFF67C01252615A568412A1C81E3EDBCF6113739B; uin_cookie=928113230"}
# 隔壁热点
p_url = "http://api.xiequ.cn/VAD/GetIp.aspx?act=get&uid=101702&vkey=4974FBE1E35DC0991E75708F70B01159&num=1&time=30&plat=0&re=0&type=0&so=1&ow=1&spl=1&addr=&db=1"
# 联通热点
# p_url = "http://api.xiequ.cn/VAD/GetIp.aspx?act=get&uid=115973&vkey=E5A3B958067077CE9698C262377BD347&num=1&time=30&plat=0&re=0&type=0&so=1&ow=1&spl=1&addr=&db=1"
# proxies = {"http": ip, "https": ip}
def get_ip():
for i in range(10):
try:
p_res = requests.request("GET", url=p_url, timeout=10).json()
# n = random.randint(0, len(p_res["data"]))
ip = str(p_res["data"][0]["IP"]) + ":" + str(p_res["data"][0]["Port"])
return {"http": ip, "https": ip}
except Exception as e:
print(repr(e))
def s_qmkg(n):
for j in range(100):
try:
res = requests.request("GET", url=url, headers=header, timeout=10, proxies=n)
print(res.text, res.status_code)
print("ip是%s,第%s次" % (n, j,))
except Exception as e:
print("需要切换ip:%s,%s" % (n, repr(e),))
def run_test():
ip = get_ip()
# start_time = time.time()
# 瞬间启动1000个线程调用同一个ip
for j in range(200):
# end_time = time.time()
print("当前是第%s个线程, ip是%s" % (j, ip,))
# 当时间超过30秒立即跳出本次循环,跟换下一个ip
# if int(end_time - start_time) > 30:
# break
t1 = threading.Thread(target=s_qmkg, args=(ip,))
t1.start()
while True:
run_test()
time.sleep(30)
project1
于 2023-05-11 22:23:09 首次发布