原帖发在内版被系统过期自动隐藏了,看到有人还需要,就自己创建节点重新发表一次,不喜直接划走
之前薅的 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 搭建节点,不会封号,放心
24
45
45 条回复
排序