pythonマルチスレッド内部エージェントが使用可能かどうかを検証
1935 ワード
社内エージェントは常に問題が発生するため、このスクリプトを書いてエージェント検出を行います.
テキスト形式は次のとおりです.
#!/usr/bin/python3
# coding=utf-8
import telnetlib
import threading
import json
import requests
from multiprocessing.dummy import Pool as ThreadPool
def msg(text):
#
headers = {'Content-Type': 'application/json;charset=utf-8'}
api_url = "https://oapi.dingtalk.com/robot/send"
json_text = {
"msgtype": "text",
"text": {
"content": text
},
"at": {
"atMobiles": [
"11"
],
"isAtAll": False
}
}
print(requests.post(api_url, json.dumps(json_text), headers=headers).content)
def proxy():
with open("/root/work/proxy_check/proxyip.txt", 'r', encoding="utf-8") as f:
for line in f:
line = line.strip().split(' ')
# ip_list_queue.put(line)
ip_arg.append(line)
def check(ip,ip_port):
try:
telnetlib.Telnet(ip, port=ip_port, timeout=5)
#requests.get('http://ip.chinaz.com/',timeout=5, proxies={ "http": "http://"+ ip + ":" + ip_port }) #
except:
print("%s " % ip)
warn_list.append(ip)
else:
pass
print("%s " % ip)
warn_list=[]
ip_arg=[]
proxy()
pool = ThreadPool(30)
# pool.map(check,ip_arg) #
pool.starmap(check,ip_arg)
pool.close()
pool.join()
if warn_list:
msg("%s " % warn_list)
#print("%s " % warn_list)
else:
#print(" ")
msg(" ")
テキスト形式は次のとおりです.
shell ip+port
xxx.xxx.xxx.146 59723
xxx.xxx.xxx.147 59724
xxx.xxx.xxx.148 59725
xxx.xxx.xxx.149 59726
xxx.xxx.xxx.150 59727