Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何修改all只获取ip:port #778

Open
shaobeipan opened this issue Dec 7, 2023 · 3 comments
Open

如何修改all只获取ip:port #778

shaobeipan opened this issue Dec 7, 2023 · 3 comments

Comments

@shaobeipan
Copy link

shaobeipan commented Dec 7, 2023

如何修改all只获取ip:port 其它的数据不需要。
比如这样
127.0.0.1:8080
127.0.0.1:8080
127.0.0.1:8080
127.0.0.1:8080

@ddayhcom
Copy link

ddayhcom commented Dec 14, 2023

源码不会修改 但是我也需要用这个 所以我是用PHP做了一个网页中转的 仅供参考

每次获取一个代理的代码是 
<?php
// 获取API返回的JSON数据
$content = file_get_contents('http://127.0.0.1:5010/get');

// 将JSON数据转换为关联数组
$data = json_decode($content, true);

// 判断是否成功获取到代理IP
if ($data['proxy']) {
  // 将代理IP输出为文本格式,每行一个IP:端口
  echo $data['proxy'] . "\n";
} else {
  echo '127.0.0.1';
}
?>




获取所有IP的代码为 

<?php

$url = 'http://127.0.0.1:5010/all';
$content = file_get_contents($url);
$data = json_decode($content, true);

if (!empty($data)) {
    foreach ($data as $item) {
        echo $item['proxy'] . "\n";
    }
} else {
    echo "No proxies found.";
}

@shaobeipan
Copy link
Author

感谢楼上的帮助。
我已经修改好了。
all最后位置替换成return '\n'.join([str(_.proxy) for _ in proxies]) 就可以

@QvQ000
Copy link

QvQ000 commented Mar 28, 2024

api_list = [
{"url": "/get", "params": "type: ''https'|''", "desc": "get a proxy"},
{"url": "/pop", "params": "", "desc": "get and delete a proxy"},
{"url": "/delete", "params": "proxy: 'e.g. 127.0.0.1:8080'", "desc": "delete an unable proxy"},
{"url": "/all", "params": "type: ''https'|''", "desc": "get all proxy from proxy pool"},
{"url": "/count", "params": "", "desc": "return proxy count"},
{"url": "/free_api/", "params": "", "desc": "return all proxies in plain text format, one per line"} #这里我增加了这行代码
下面我增加了
@app.route('/free_api/')
def free_api():
proxies = proxy_handler.getAll() # 获取所有代理
formatted_proxies = [proxy.to_dict['proxy'] for proxy in proxies] # 直接使用 'proxy' 键获取完整的 'IP:Port'
return Response("\n".join(formatted_proxies), mimetype='text/plain') # 以纯文本形式返回代理列表
我乱改的 但是返回的是纯文本ip:port 一行一个
如果在windows上某些软件能正常读取api返回内容你需要将"\n".join改成"\r\n".join

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants