注册 登录
n/haoyihao · 3 个月前 · 已编辑 · 1480 次浏览
u/1panel黄金
n/haoyihaou/1panel · 3 个月前

【存档】免费白嫖日本/韩国原生家宽节点!基于 Serv00 + PHP 打造专属 Mihomo 订阅接口

原帖发在内版被系统过期自动隐藏了,看到有人还需要,就自己创建节点重新发表一次,不喜直接划走

之前薅的 Serv00 免费vps服务器一直闲着不知道干点儿啥
不记得在哪里看到的, VPNGate 提供海量日本/韩国志愿家宽节点
VPNGate 官方仅提供原始 CSV 和单个 .ovpn 格式,无法直接给 Mihomo 使用
因此需要一个自动化转换层,这不就有了嘛,终于可以让 Serv00 派上用场了

废话不多说,直接上代码,保存为 openvpn.php,上传到 Serv00 服务器上即可使用

<?php
// 屏蔽提示信息并设置脚本响应头/超时限制
error_reporting(E_ALL & ~E_NOTICE);
ini_set('display_errors', 0);
set_time_limit(60);

// ================= 路由与密钥保护设置 =================
const AUTH_TOKEN = "JJmi1vwutFHfssyH8Ym88NQNp2pZQ6Lo";

$requestToken = $_GET['token'] ?? '';

if ($requestToken !== AUTH_TOKEN) {
    http_response_code(401);
    header("Content-Type: text/plain; charset=utf-8");
    echo "Unauthorized: 密钥错误或未提供";
    exit;
}
// =====================================================

$cacheFile = __DIR__ . '/vpngate_cache.yaml';
$expireSeconds = 3600; // 缓存 1 小时
$vpngateUrl = "https://www.vpngate.net/api/iphone/";

try {
    // 1. 检查本地文件缓存
    if (file_exists($cacheFile) && (time() - filemtime($cacheFile) < $expireSeconds)) {
        $cachedYaml = file_get_contents($cacheFile);
        if ($cachedYaml !== false) {
            header("Content-Type: text/yaml; charset=utf-8");
            header('Content-Disposition: inline; filename=openvpn.yaml');
            header("Access-Control-Allow-Origin: *");
            header("X-Cache-Status: HIT");
            echo $cachedYaml;
            exit;
        }
    }

    // 2. 缓存未命中,获取节点
    $nodes = fetchAndParseVPNGate($vpngateUrl);

    if (empty($nodes)) {
        http_response_code(404);
        header("Content-Type: text/plain; charset=utf-8");
        echo "未解析到有效的 VPNGate 节点";
        exit;
    }

    // 3. 手动转换为 YAML 字符串
    $yamlData = dumpToYaml($nodes);

    // 4. 写入本地文件缓存
    @file_put_contents($cacheFile, $yamlData, LOCK_EX);

    // 5. 返回生成的 YAML
    header("Content-Type: text/yaml; charset=utf-8");
    header('Content-Disposition: inline; filename="openvpn.yaml"');
    header("Access-Control-Allow-Origin: *");
    header("X-Cache-Status: MISS");
    echo $yamlData;

} catch (Exception $err) {
    http_response_code(500);
    header("Content-Type: text/plain; charset=utf-8");
    echo "处理失败: " . $err->getMessage();
}

/**
 * 手动将节点对象数组转为标准 Mihomo YAML 格式
 */
function dumpToYaml(array $nodes): string {
    $yaml = "proxies:\n";
    foreach ($nodes as $node) {
        $yaml .= '  - name: "' . escapeYamlString($node['name']) . '"' . "\n";
        $yaml .= "    type: {$node['type']}\n";
        $yaml .= "    server: {$node['server']}\n";
        $yaml .= "    port: {$node['port']}\n";
        $yaml .= "    proto: {$node['proto']}\n";

        if (!empty($node['cipher'])) $yaml .= "    cipher: {$node['cipher']}\n";
        if (!empty($node['auth']))   $yaml .= "    auth: {$node['auth']}\n";

        // 针对长文本证书(ca/cert/key),采用 YAML 多行缩进写法 (|+ 格式)
        if (!empty($node['ca']))   $yaml .= "    ca: |+\n" . indentText($node['ca'], 6) . "\n";
        if (!empty($node['cert'])) $yaml .= "    cert: |+\n" . indentText($node['cert'], 6) . "\n";
        if (!empty($node['key']))  $yaml .= "    key: |+\n" . indentText($node['key'], 6) . "\n";
    }
    return $yaml;
}

function escapeYamlString(string $str): string {
    return str_replace(['\\', '"'], ['\\\\', '\"'], $str);
}

function indentText(string $text, int $spaces): string {
    $prefix = str_repeat(' ', $spaces);
    $lines = explode("\n", $text);
    $indented = array_map(fn($line) => $prefix . $line, $lines);
    return implode("\n", $indented);
}

/**
 * 获取并解析 VPNGate CSV 数据
 */
function fetchAndParseVPNGate(string $url): array {
    $options = [
        "http" => [
            "method" => "GET",
            "header" => "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36\r\n" .
                        "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n",
            "timeout" => 15
        ]
    ];
    $context = stream_context_create($options);
    $text = @file_get_contents($url, false, $context);

    if ($text === false) {
        throw new Exception("抓取 VPNGate 数据失败,请检查网络或服务器配置");
    }

    $lines = preg_split('/\r?\n/', $text);
    $nodes = [];

    foreach ($lines as $line) {
        $line = trim($line);
        if ($line === '') continue;

        $record = explode(',', $line);
        if (empty($record)) continue;

        $firstCol = trim($record[0]);
        if (str_starts_with($firstCol, '#') || str_starts_with($firstCol, '*')) {
            continue;
        }

        $lastCol = trim(end($record));
        if (empty($lastCol)) continue;

        $ovpnText = base64_decode($lastCol, true);
        if ($ovpnText === false) continue;

        $nodeName = "VPNGate-" . $record[0];
        if (isset($record[6]) && !empty(trim($record[6]))) {
            $nodeName = trim($record[6]) . "-" . $record[0];
        }

        if (str_contains($nodeName, "public")) {
            continue;
        }

        $node = convertOvpnToMihomo($nodeName, $ovpnText);

        if ($node && isset($node['proto']) && $node['proto'] === "udp") {
            continue;
        }

        if ($node && !empty($node['server'])) {
            $nodes[] = $node;
        }
    }

    return $nodes;
}

/**
 * 解析 .ovpn 文本并提取参数
 */
function convertOvpnToMihomo(string $name, string $ovpn): ?array {
    $node = [
        'name' => $name,
        'type' => "openvpn"
    ];

    $lines = explode("\n", $ovpn);
    foreach ($lines as $line) {
        $line = trim($line);

        if (preg_match('/^\s*remote\s+([^\s]+)\s+(\d+)/i', $line, $matchRemote)) {
            $node['server'] = $matchRemote[1];
            $node['port'] = (int)$matchRemote[2];
        }

        if (preg_match('/^\s*proto\s+(tcp|udp|tcp-client|udp-client)/i', $line, $matchProto)) {
            if (str_starts_with(strtolower($matchProto[1]), "tcp")) {
                $node['proto'] = "tcp";
            } else {
                $node['proto'] = "udp";
            }
        }

        if (preg_match('/^\s*cipher\s+([^\s]+)/i', $line, $matchCipher)) {
            $node['cipher'] = $matchCipher[1];
        }

        if (preg_match('/^\s*auth\s+([^\s]+)/i', $line, $matchAuth)) {
            $node['auth'] = $matchAuth[1];
        }
    }

    $ca = extractXMLBlock($ovpn, "ca");
    if (!empty($ca)) $node['ca'] = $ca;

    $cert = extractXMLBlock($ovpn, "cert");
    if (!empty($cert)) $node['cert'] = $cert;

    $key = extractXMLBlock($ovpn, "key");
    if (!empty($key)) $node['key'] = $key;

    if (empty($node['server'])) {
        return null;
    }

    if (empty($node['proto'])) {
        $node['proto'] = "udp";
    }

    return $node;
}

function extractXMLBlock(string $content, string $tag): string {
    $pattern = "/<" . preg_quote($tag, '/') . ">([\s\S]*?)<\/" . preg_quote($tag, '/') . ">/i";
    if (preg_match($pattern, $content, $match) && !empty($match[1])) {
        return trim($match[1]);
    }
    return "";
}

当然这些家宽节点在国内大概率无法直连
这就需要自己找个前置节点,至于去哪里搞到线路好还便宜的节点那是 另外一篇帖子了,这里不展开讲
找好前置节点后,配置好规则分组,导入到自己熟悉的客户端就可以使用了,你的mihomo配置文件大概长这样

proxies:
    - 你的前置节点配置

proxy-providers:
    provider1:
        interval: 3600
        override:
            dialer-proxy: 你的前置节点名称
        path: ./provider/openvpn.yaml
        type: http
        url: https://789.nx.kg/openvpn.php?token=JJmi1vwutFHfssyH8Ym88NQNp2pZQ6Lo

我比较懒,就不写规则分组了,将以上配置直接导入到 Pandora-Box 可直接使用,这个客户端直接支持不写规则分组导入节点或者配置

最终效果如下图

节点

家宽节点质量如下图

至于网速嘛,这得看你前置节点

速度

最后,眼尖的你可能发现我的Serv00提供的订阅地址了

https://789.nx.kg/openvpn.php?token=JJmi1vwutFHfssyH8Ym88NQNp2pZQ6Lo

拿去拿去

题外话:这种方法不是使用 Serv00 搭建节点,不会封号,放心

25
45
登录后参与讨论。
u/udc2b6nr 广告
QuicksilverVPN

快银 VPN,一键连接全球节点,线路稳定、延迟低。支持 Windows、macOS 等多平台,TUN 全局模式覆盖全部应用流量。无需复杂配置,下载即用。

umami.dnsl.top 了解更多

45 条回复

排序
  1. Yang-iyu 白银 3 个月前 #2

    大佬牛逼,我插眼+1

    2
  2. xiaoyi669 💬 钻石 钻石会员 3 个月前 #3

    参与留存一下

    2
  3. duyouqian 白银 3 个月前 #4

    插眼+1

    4
  4. DaniG 黄金 3 YEARS 3 个月前 #5

    感觉很不错

    3
  5. huwei 黄金 3 个月前 #6

    感谢大佬

    2
  6. yybbtech 🎧 铂金 3 个月前 #7

    这回必须插眼了

    0
  7. for 黄金 3 个月前 #8

    插眼,留着备用。大佬牛皮

    0
  8. IPLAY4LOVE 黄金 3 个月前 #9

    已经点赞收藏了 ,大佬太强了,赶紧学习一下

    0
  9. xxooxx 青铜 3 个月前 #10

    openvpn的格式,好像很多都不支持。

    2
  10. 1panel 黄金 楼主 3 个月前 #11
    回复 @xxooxx:openvpn的格式,好像很多都不支持。

    基于 mihomo 和 sing-box 最新内核的客户端都是支持的

    2
  11. shine1991 黄金 3 YEARS 3 个月前 #12

    插眼等有serv00

    2
  12. 1panel 黄金 楼主 3 个月前 #13
    回复 @shine1991:插眼等有serv00

    没有serv00也行,可以找ai改写成cloudflare的works脚本,部署也是一样的

    2
  13. shine1991 黄金 3 YEARS 3 个月前 #14
    回复 @1panel:没有serv00也行,可以找ai改写成cloudflare的works脚本,部署也是一样的

    谢谢佬提醒我试试看 :xhj16:

    0
  14. shine1991 黄金 3 YEARS 3 个月前 #15
    回复 @1panel:没有serv00也行,可以找ai改写成cloudflare的works脚本,部署也是一样的

    用AI修改完成。把token添加到环境变量使用感谢大佬

    1
  15. QAQsmile 白银 2 个月前 #16

    插眼

    1
  16. leexore 白银 2 个月前 #17

    感谢楼主,只看不用

    1
  17. xiaozx 💤 黄金 3 YEARS 2 个月前 #18

    感谢分享!

    1
  18. newbietan 黄金 3 YEARS 2 个月前 #19

    可以,很强,可惜没serv00账号

    2
  19. qwang 黄金 3 YEARS 2 个月前 #20

    插眼

    1
  20. Make1 🚗 黄金 3 YEARS 2 个月前 #21

    可惜了,QX无法使用

    1
  21. smzdm2025 白银 2 个月前 #22

    可以,有空搭建一个

    1
  22. 1panel 黄金 楼主 2 个月前 #23
    回复 @newbietan:可以,很强,可惜没serv00账号

    没有serv00也行,可以找ai改写成cloudflare的works脚本,去部署也可以,比serv00响应更快

    0
  23. jeco 黄金 2 个月前 #24

    哇大佬牛逼啊,这个必须收藏了!

    1
  24. 906964928 青铜 2 个月前 #25

    支持一波

    1
  25. 906964928 青铜 2 个月前 #26

    大佬你提供的订阅地址哪些手机端app可以使用,试了FL clash,karing都不行

    0
  26. hankswang01 黄金 不离不弃 2 个月前 #27

    不明觉厉啊

    1
  27. rzo 白银 3 YEARS 2 个月前 #28
    回复 @906964928:大佬你提供的订阅地址哪些手机端app可以使用,试了FL clash,karing都不行

    FLclash可以,不是直接用的。你要先有个flclash可以用的配置,然后在proxy-providers中配置链式代理

    0
  28. 906964928 青铜 2 个月前 #29
    回复 @rzo:FLclash可以,不是直接用的。你要先有个flclash可以用的配置,然后在proxy-providers中配置链式代…

    你看我配置的有问题吗,我导入FL clash提示有错误

    0