解决:青龙API请求失败,请检查网络 的方法
插曲:需要京豆小组件制作的找我,生成只需要10元,超低价!
青龙API请求失败,请检查网络
青龙执行任务,如果执行任务时间过长就会黑ip,应对解决ip黑名单问题,利用代理来实现切换出网ip
本想着青龙面板的任务主要是nodejs环境居多,便想着搞一个nodejs代理,但是发现我自己还是喜欢python和go语言写得脚本较多, 然后是变成了修改linux代理,因为青龙是用docker容器跑的服务,又演变成修改docker代理,docker修改代理又有局部或者全局变量,最后演变成设置linux代理来解决其他得http或者https得请求,甭管您是nodejs还是python又或者go,总是要经过系统网络,那就修改 docker容器里面得linux的网络即可
选择clash的原因是支持api
clash代理
mkdir /opt/clash && cd $_
wget '订阅地址' -O config.yaml
docker run -d --name=clash -v "$PWD/config.yaml:/root/.config/clash/config.yaml" -p "7890:7890" -p "9090:9090" --restart=unless-stopped dreamacro/clash
通过api接口打开clash,下面是手机得两个网址(电脑是ubuntu火狐可以连接chrome连接不上安全问题,建议用火狐浏览器)
建议clash配置修改成全局代理(主要是rules)
vi config.yaml
# HTTP 端口
port: 7890
# SOCKS5 端口
socks-port: 7891
# Linux 及 macOS 的 redir 端口
# redir-port: 7892
allow-lan: true
# 仅适用于设置 allow-lan 为 true 时
# "*": 绑定所有 IP 地址
# 192.168.122.11: 绑定单个 IPv4 地址
# "[aaaa::a8aa:ff:fe09:57d8]": 绑定单个 IPv6 地址
# bind-address: "*"
# Rule / Global / Direct (默认为 Rule 模式)
mode: Rule
# 设置输出日志的等级 (默认为 info)
# info / warning / error / debug / silent
log-level: info
# RESTful API for clash
external-controller: 0.0.0.0:9090
# you can put the static web resource (such as clash-dashboard) to a directory, and clash would serve in `${API}/ui`
# input is a relative path to the configuration directory or an absolute path
# external-ui: folder
# Secret for RESTful API (Optional)
# secret: ""
# 实验性功能
experimental:
ignore-resolve-fail: true # 忽略 DNS 解析失败,默认值为true
proxies:
# 支持的协议及加密算法示例请查阅 Clash 项目 README 以使用最新格式:https://github.com/Dreamacro/clash/blob/master/README.md
# Shadowsocks 支持的加密方式:
# aes-128-gcm aes-192-gcm aes-256-gcm
# aes-128-cfb aes-192-cfb aes-256-cfb
# aes-128-ctr aes-192-ctr aes-256-ctr
# rc4-md5 chacha20-ietf xchacha20
# chacha20-ietf-poly1305 xchacha20-ietf-poly1305
# Shadowsocks
- name: "ss"
type: ss
server: ca03.yootoo6oocoo1oo.xyz
port: 4982
cipher: rc4-md5
password: Z4kiWW
udp: true
- name: "socks5"
type: socks5
server: 192.168.1.111
port: 3213
# Shadowsocks(simple-obfs)
- name: "ss-obfs"
type: ss
server: server
port: 443
cipher: chacha20-ietf-poly1305
password: "password"
plugin: obfs
plugin-opts:
mode: tls
host: example.com
# Shadowsocks(v2ray-plugin)
- name: "ss-v2ray"
type: ss
server: server
port: 443
cipher: chacha20-ietf-poly1305
password: "password"
plugin: v2ray-plugin
plugin-opts:
mode: websocket # no QUIC now
# tls: true # wss
# skip-cert-verify: true
# host: bing.com
# path: "/"
# mux: true
# headers:
# custom: value
# VMess
- name: "v2ray"
type: vmess
server: server
port: 443
uuid: a3482e88-686a-4a58-8126-99c9df64b7bf
alterId: 64
cipher: auto
# udp: true
# tls: true
# tls-hostname: 填写伪装域名
# skip-cert-verify: true
# network: ws
# ws-path: /path
# ws-headers: #这一行后面不要写东西
# Host: v2ray.com # 填写伪装域名
# Trojan
- name: "trojan"
type: trojan
server: dev.dra-m.com
port: 29895
password: hV3Fwjyvig
udp: true
sni: dev.dra-m.com # 填写伪装域名
#alpn:
# - h2
# - http/1.1
skip-cert-verify: true
# 代理组策略
# 策略组示例请查阅 Clash 项目 README 以使用最新格式:https://github.com/Dreamacro/clash/blob/master/README.md
proxy-groups:
# 代理节点选择
- name: "PROXY"
type: select
proxies:
- "ss"
- "socks5"
- "ss-obfs"
- "ss-v2ray"
- "v2ray"
- "trojan"
# 规则
rules:
- MATCH,PROXY
可以把订阅节点放在示例配置文件proxies里面
clash api调用(这里用curl演示,可以用go或者pyhon自动获取节点然后测速,并每小时切换节点地址)
设置代理(青龙)
## diy_linux_proxy
CLASH_HOST="192.168.2.18"
CLASH_PORT="9090"
CHAINS=$(curl --silent --location --header "Content-Type: application/json" --request GET "http://${CLASH_HOST}:${CLASH_PORT}/proxies"|jq -r ".proxies.PROXY.all[]" |sed -n $[$RANDOM%221]p)
echo ${CHAINS}
curl --location --request PUT "http://${CLASH_HOST}:${CLASH_PORT}/proxies/PROXY" \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "'"${CHAINS}"'"
}'
export proxy="http://${CLASH_HOST}:7890"
export http_proxy=$proxy
export https_proxy=$proxy
export ftp_proxy=$proxy
export no_proxy="localhost, 127.0.0.1, ::1"
青龙测试日志如下
python测试代码
#!/usr/bin/env python3
# -*- coding:utf-8 _*-
"""
cron: 30 9 * * *
new Env('get_ip_public');
"""
import socket
import requests
import re
from sendNotify import send
title = ''
content = ''
class IP:
@staticmethod
def get_ip_public():
"""
获取本机公网IP
:return:
"""
try:
text = requests.get("http://txt.go.sohu.com/ip/soip").text
ip_public = re.findall(r'\d+.\d+.\d+.\d+', text)[0]
return ip_public
except:
return '0.0.0.0'
@staticmethod
def get_ip_local():
"""
查询本机内网IP
:return:
"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
if __name__ == '__main__':
print("内网IP:{}".format(IP.get_ip_local()))
print("外网IP:{}".format(IP.get_ip_public()))
title= "get_ip_public"
content = IP.get_ip_public()
send(title, content)
nojs测试代码
var request = require('request');
var options = {
'method': 'GET',
'url': 'https://api.ip.sb/ip',
'headers': {
}
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
如果喜欢用python自动切换节点如下,脚本临时写得没有写自动过滤延迟高得节点,谁写好可以推过来哈,没时间折腾,只是为了测试功能是否实现而已
#!/usr/bin/env python3
# -*- coding:utf-8 _*-
"""
cron: 50 23 * * *
new Env('jd_sync_ck')
"""
import os
import requests
import json
import random
payload = {}
headers = {}
# clash所在的服务器ip
clash_host = "192.168.1.61"
# clash ui对外暴露的端口
clash_port = "9090"
def get_proxies():
url = "http://%s:%s/proxies" % (clash_host, clash_port)
r = requests.request("GET", url, headers=headers, data=payload)
print(r.text)
item = json.loads(r.text)['proxies']['PROXY']['all']
return item
def chains_delay():
url = "http://%s:%s/proxies/trojan/delay?timeout=10000&url=http://www.gstatic.com/generate_204" % (
clash_host, clash_port)
r = requests.request("GET", url, headers=headers, data=payload)
item = json.loads(r.text)['delay']
print(item)
def selector_chains(chains):
url = "http://%s:%s/proxies/PROXY" % (clash_host, clash_port)
payload = json.dumps({
"name": chains
})
headers = {
'Content-Type': 'application/json'
}
r = requests.request("PUT", url, headers=headers, data=payload)
print(r.text)
def main():
if "clash_host" in os.environ and os.environ["clash_host"]:
BARK = os.environ["clash_host"]
if "clash_port" in os.environ and os.environ["clash_port"]:
BARK = os.environ["clash_port"]
chains_list = get_proxies()
chains = random.choice(chains_list)
print("本次选择的节点是 %s" % chains)
# chains_delay()
selector_chains(chains)
if __name__ == "__main__":
main()
后记
临时测试了下,可以完美解决”青龙API请求失败,请检查网络”得问题,脚本等完善之后再放出来给大家用把.思路给大伙说了。
文章作者:?Myki
博主还没有测试,最近没有空….