# Install-WireGuardServer.ps1 $interfaceName = "Ethernet0" $wgPath = "C:\Program Files\WireGuard" $confPath = "$wgPath\wg0.conf" $ipv4Pub = "209.159.148.38" $ipv6Pub = "2604:a00:50:1ed:8842:dd89:c80f:3fcd" $vpnIPv4 = "10.10.0.1/24" $vpnIPv6 = "fd86:ea04:1111::1/64" $port = 51820 if (-Not (Test-Path "$wgPath\wg.exe")) { Write-Host "WireGuard non installé. Télécharge-le depuis https://www.wireguard.com/install/" -ForegroundColor Red exit } Set-Location $wgPath .\wg.exe genkey | Tee-Object -Variable PrivateKey | .\wg.exe pubkey > publickey $PrivateKey = $PrivateKey.Trim() $PublicKey = Get-Content publickey | Out-String $PublicKey = $PublicKey.Trim() Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -Name "IPEnableRouter" -Value 1 Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip6\Parameters" -Name "DisabledComponents" -Value 0 New-NetFirewallRule -DisplayName "WireGuard UDP $port" -Direction Inbound -Protocol UDP -LocalPort $port -Action Allow -Profile Any $conf = @" [Interface] PrivateKey = $PrivateKey Address = $vpnIPv4, $vpnIPv6 ListenPort = $port PostUp = netsh interface ipv4 set interface "$interfaceName" forwarding=enabled PostUp = netsh interface ipv6 set interface "$interfaceName" forwarding=enabled PostUp = netsh interface ipv4 set interface "WireGuard" forwarding=enabled PostUp = netsh interface ipv6 set interface "WireGuard" forwarding=enabled PostUp = netsh advfirewall firewall add rule name="Allow WireGuard In" dir=in action=allow protocol=UDP localport=$port PostUp = netsh advfirewall firewall add rule name="Allow WireGuard Interface" dir=in action=allow interface="WireGuard" PostDown = netsh advfirewall firewall delete rule name="Allow WireGuard In" PostDown = netsh advfirewall firewall delete rule name="Allow WireGuard Interface" "@ $conf | Out-File -Encoding ASCII -FilePath $confPath -Force Write-Host "`n✅ WireGuard configuré avec succès !" Write-Host "➡️ Clé publique du serveur à transmettre aux clients : $PublicKey" Write-Host "➡️ Lancement : Ouvre WireGuard GUI, charge wg0.conf et clique sur 'Activate' ou utilise ce script :" Write-Host "`"$wgPath\wg.exe`" quick up wg0"