用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/ffsshhttiikk/opencode-agents-skills --skill vpn命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | vpn |
| description | Virtual Private Network implementation and configuration |
| category | networking |
| difficulty | intermediate |
| tags | ["vpn","security","tunnel","encryption"] |
| author | OpenCode Community |
| version | 1 |
| last_updated | 2024-01-15T00:00:00.000Z |
I am VPN, a technology that creates secure, encrypted connections (tunnels) over public networks to extend private networks securely. I enable remote users to access resources as if connected directly to the private network. I support various protocols including OpenVPN, WireGuard, IPsec, and SSL/TLS-based VPNs. I provide encryption for data in transit, authentication of connecting clients, and IP address translation. I enable site-to-site connectivity between geographically distributed offices. I help organizations maintain security boundaries while supporting remote workforces. Modern VPNs like WireGuard offer improved performance and simpler configurations than traditional solutions.
Tunneling: Encapsulating packets within other protocols for transport across networks.
Encryption Protocols: WireGuard (Noise protocol), OpenVPN (SSL/TLS), IPsec (ESP, AH).
Authentication Methods: Pre-shared keys, certificates, multi-factor authentication.
Routing: Split tunneling vs full tunneling, routing tables.
Kill Switch: Network cut-off when VPN connection drops.
Protocol Selection: WireGuard for performance, OpenVPN for compatibility, IPsec for enterprise.
#!/bin/bash
# WireGuard VPN Server Setup Script
set -e
# Configuration variables
WG_INTERFACE="wg0"
WG_PORT=51820
WG_NETWORK="10.0.0.0/24"
SERVER_PRIVATE_KEY="REPLACE_WITH_PRIVATE_KEY"
SERVER_PUBLIC_KEY="REPLACE_WITH_PUBLIC_KEY"
# Generate keys
generate_keys() {
umask 077
wg genkey | tee privatekey | wg pubkey > publickey
cat privatekey
cat publickey
}
# Install WireGuard
install_wireguard() {
apt update
apt install -y wireguard wireguard-tools
# Enable IP forwarding
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
echo "net.ipv6.conf.all.forwarding=1" >> /etc/sysctl.conf
sysctl -p
}
# Configure server
configure_server() {
cat > /etc/wireguard/${WG_INTERFACE}.conf << EOF
[Interface]
Address = ${WG_NETWORK}
ListenPort = ${WG_PORT}
PrivateKey = ${SERVER_PRIVATE_KEY}
PostUp = iptables -A FORWARD -i %i -j ACCEPT
PostDown = iptables -D FORWARD -i %i -j ACCEPT
PostUp = iptables -t nat -A POSTROUTING -s ${WG_NETWORK} -o eth0 -j MASQUERADE
PostDown = iptables -t nat -D POSTROUTING -s ${WG_NETWORK} -o eth0 -j MASQUERADE
# Client: alice
[Peer]
# PublicKey = CLIENT_PUBLIC_KEY
# AllowedIPs = 10.0.0.2/32
# Client: bob
[Peer]
# PublicKey = CLIENT_PUBLIC_KEY
# AllowedIPs = 10.0.0.3/32
EOF
chmod 600 /etc/wireguard/${WG_INTERFACE}.conf
}
# Add client peer
add_peer() {
local CLIENT_NAME=$1
local CLIENT_PUBLIC_KEY=$2
CLIENT_IP=
>> /etc/wireguard/.conf <<
wg syncconf <(wg-quick strip )
}
() {
systemctl wg-quick@
systemctl start wg-quick@
wg show
}
() {
CLIENT_NAME=
SERVER_PUBLIC_IP=
CLIENT_PRIVATE_KEY=
> ~/.conf <<
600 ~/.conf
}
() {
;
clear
wg show
wg show dump | -n +2 | awk
5
}
install)
install_wireguard
configure_server
enable_service
;;
add-peer)
add_peer
;;
client-config)
generate_client_config
;;
monitor)
monitor_connections
;;
*)
;;
# OpenVPN Server Configuration
# /etc/openvpn/server.conf
# Protocol and port
proto udp
port 1194
# Device and tunneling
dev tun
topology subnet
# Certificate paths
ca ca.crt
cert server.crt
key server.key
dh dh2048.pem
tls-auth ta.key 0
# Network configuration
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
push "route 192.168.10.0 255.255.255.0"
push "route 192.168.20.0 255.255.255.0"
push "dhcp-option DNS 8.8.8.8"
push "dhcp-option DNS 8.8.4.4"
# Client-to-client communication
client-to-client
duplicate-cn
# Keepalive and compression
keepalive 10 120
compress lz4-v2
push "compress lz4-v2"
# Cryptography
cipher AES-256-GCM
auth SHA256
# Persistence
persist-key
persist-tun
# Status and logging
status openvpn-status.log
log /var/log/openvpn.log
verb 3
# Maximum clients
max-clients 100
# Security enhancements
user nobody
group nogroup
# MTU settings
mtu-test
tun-mtu 1500
# Redirect gateway for full tunneling
;push "redirect-gateway def1 bypass-dhcp"
import socket
import struct
import threading
import time
from dataclasses import dataclass
from typing import Optional, Dict, List
from enum import Enum
class VPNProtocol(Enum):
OPENVPN = "openvpn"
WIREGUARD = "wireguard"
IPSEC = "ipsec"
@dataclass
class VPNClientConfig:
protocol: VPNProtocol
server_address: str
port: int
username: str
password: str
ca_cert: Optional[str] = None
client_cert: Optional[str] = None
client_key: Optional[str] = None
dns_servers: List[str] = None
routes: List[str] = None
split_tunnel: bool = False
class VPNClient:
def __init__(self, config: VPNClientConfig):
self.config = config
self.socket: [socket.socket] =
.tunnel_interface =
.connected =
.reconnecting =
.event_callbacks: [, []] = {}
():
event .event_callbacks:
.event_callbacks[event] = []
.event_callbacks[event].append(callback)
():
callback .event_callbacks.get(event, []):
:
callback(*args)
Exception e:
()
() -> :
:
._emit()
.config.protocol == VPNProtocol.WIREGUARD:
._connect_wireguard(timeout)
.config.protocol == VPNProtocol.OPENVPN:
._connect_openvpn(timeout)
:
NotImplementedError()
Exception e:
._emit(, e)
() -> :
wgconfig.wgconfig wg
wgconf = wg.WGConfig()
wgconf.add_interface(
privatekey=.config.client_key,
address=,
dns=.config.dns_servers []
)
wgconf.add_peer(
publickey=._get_server_public_key(),
endpoint=,
allowedips=.config.routes [],
persistentkeepalive=
)
wgconf.write()
:
wgconf.apply()
.connected =
._emit()
Exception e:
._emit(, e)
() -> :
subprocess
os
config_lines = [
,
,
,
,
,
,
,
,
,
,
,
]
.config.ca_cert:
config_lines.append()
.config.client_cert:
config_lines.append()
.config.client_key:
config_lines.append()
.config.split_tunnel:
config_lines.append()
route .config.routes []:
config_lines.append()
(, ) f:
f.write(.join(config_lines))
.openvpn_process = subprocess.Popen(
[, , ],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
preexec_fn=os.setsid
)
start_time = time.time()
time.time() - start_time < timeout:
._check_openvpn_connected():
.connected =
._emit()
time.sleep()
._emit(, TimeoutError())
() -> :
:
result = subprocess.run(
[, , , ],
capture_output=,
timeout=
)
result.returncode == result.stdout.decode()
:
():
.config.protocol == VPNProtocol.WIREGUARD:
:
subprocess.run([, , ], capture_output=)
:
.config.protocol == VPNProtocol.OPENVPN:
(, ):
.openvpn_process.terminate()
.openvpn_process.wait()
.connected =
._emit()
() -> :
{
: .connected,
: .config.protocol.value,
: ,
: time.time()
}
() -> :
import time
import statistics
from typing import Dict, List, Optional
from dataclasses import dataclass
from collections import deque
@dataclass
class VPNMetrics:
latency_ms: float
jitter_ms: float
packets_sent: int
packets_received: int
packets_lost: int
bytes_sent: int
bytes_received: int
connection_time: float
class VPNPerformanceMonitor:
def __init__(self, sample_size: int = 60):
self.sample_size = sample_size
self.latency_samples = deque(maxlen=sample_size)
self.jitter_samples = deque(maxlen=sample_size)
self.packets_sent = 0
self.packets_received = 0
self.packets_lost = 0
self.bytes_sent = 0
self.bytes_received = 0
self.connection_start_time: Optional[float] = None
self.running =
.monitoring_thread =
():
.running =
.connection_start_time = time.time()
.monitoring_thread = threading.Thread(target=._monitor_loop, daemon=)
.monitoring_thread.start()
():
.running =
.monitoring_thread:
.monitoring_thread.join(timeout=)
():
.running:
:
._measure_connection()
Exception e:
()
time.sleep()
():
subprocess
start = time.time()
:
result = subprocess.run(
[, , , , , ],
capture_output=,
timeout=
)
latency = (time.time() - start) *
result.returncode == :
.latency_samples.append(latency)
.packets_received +=
:
.packets_lost +=
.packets_sent +=
Exception:
.packets_lost +=
.packets_sent +=
() -> VPNMetrics:
latencies = (.latency_samples)
jitter =
(latencies) > :
jitter = statistics.stdev(latencies) (latencies) >
connection_time =
.connection_start_time:
connection_time = time.time() - .connection_start_time
VPNMetrics(
latency_ms=statistics.mean(latencies) latencies ,
jitter_ms=jitter,
packets_sent=.packets_sent,
packets_received=.packets_received,
packets_lost=.packets_lost,
bytes_sent=.bytes_sent,
bytes_received=.bytes_received,
connection_time=connection_time
)
() -> :
metrics = .get_metrics()
loss_rate =
.packets_sent > :
loss_rate = (.packets_lost / .packets_sent) *
{
: (metrics.connection_time, ),
: {
: (metrics.latency_ms, ),
: (statistics.mean(.latency_samples), ) .latency_samples ,
: ((.latency_samples), ) .latency_samples ,
: ((.latency_samples), ) .latency_samples ,
: (statistics.stdev(.latency_samples), ) (.latency_samples) >
},
: (metrics.jitter_ms, ),
: {
: .packets_sent,
: .packets_received,
: .packets_lost,
: (loss_rate, )
},
: {
: .bytes_sent,
: .bytes_received
}
}