因为oppo的虚拟网卡,和tun打架,没法开tun模式。
但是这俩还都要用,于是查到了一个上古解决方案。
clash-verge-rev/issues/244,开关网络共享就好了。
但是每次开机都要弄,就很麻烦,让gpt帮我写了个脚本。
超级笨办法,但是有效,颇有种程序员的风采
能跑就行
$PublicAdapter = "以太网"
$TunAdapter = "vgate0"
$HoldSeconds = 2
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal($identity)
$isAdmin = $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Start-Process powershell.exe -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`""
exit
}
function Get-IcsItems {
$manager = New-Object -ComObject HNetCfg.HNetShare
$items = @()
foreach ($conn in $manager.EnumEveryConnection()) {
try {
$props = $manager.NetConnectionProps($conn)
$cfg = $manager.INetSharingConfigurationForINetConnection($conn)
$items += [PSCustomObject]@{
Name = $props.Name
DeviceName = $props.DeviceName
SharingEnabled = $cfg.SharingEnabled
SharingType = $cfg.SharingConnectionType
Config = $cfg
}
} catch {}
}
return $items
}
function Disable-AllIcs {
param($Items)
foreach ($item in $Items) {
try {
if ($item.SharingEnabled) {
Write-Host "Disable ICS on:" $item.Name
$item.Config.DisableSharing()
Start-Sleep -Milliseconds 500
}
} catch {}
}
}
$svc = Get-Service -Name SharedAccess -ErrorAction SilentlyContinue
if ($svc -and $svc.Status -ne "Running") {
Write-Host "Starting SharedAccess service..."
Start-Service -Name SharedAccess
Start-Sleep -Seconds 1
}
$items = Get-IcsItems
Write-Host ""
Write-Host "Available ICS connections:"
$items | Select-Object Name, DeviceName, SharingEnabled, SharingType | Format-Table -Auto
Write-Host ""
$public = $items | Where-Object {
$_.Name -eq $PublicAdapter -or $_.Name -like "*$PublicAdapter*" -or $_.DeviceName -like "*$PublicAdapter*"
} | Select-Object -First 1
$tun = $items | Where-Object {
$_.Name -eq $TunAdapter -or $_.Name -like "*$TunAdapter*" -or $_.DeviceName -like "*Mihomo*" -or $_.DeviceName -like "*Meta Tunnel*"
} | Select-Object -First 1
if (-not $public) {
Write-Host "Cannot find public adapter:" $PublicAdapter -ForegroundColor Red
Pause
exit 1
}
if (-not $tun) {
Write-Host "Cannot find TUN adapter. Make sure TUN is already enabled." -ForegroundColor Red
Pause
exit 1
}
try {
Write-Host "Public adapter:" $public.Name
Write-Host "TUN adapter :" $tun.Name
Write-Host ""
Write-Host "Clearing existing ICS..."
Disable-AllIcs $items
Start-Sleep -Seconds 1
$items = Get-IcsItems
$public = $items | Where-Object {
$_.Name -eq $PublicAdapter -or $_.Name -like "*$PublicAdapter*" -or $_.DeviceName -like "*$PublicAdapter*"
} | Select-Object -First 1
$tun = $items | Where-Object {
$_.Name -eq $TunAdapter -or $_.Name -like "*$TunAdapter*" -or $_.DeviceName -like "*Mihomo*" -or $_.DeviceName -like "*Meta Tunnel*"
} | Select-Object -First 1
Write-Host "Enable private sharing on TUN:" $tun.Name
$tun.Config.EnableSharing(1)
Start-Sleep -Milliseconds 800
Write-Host "Enable public sharing on:" $public.Name
$public.Config.EnableSharing(0)
Write-Host "Hold for" $HoldSeconds "seconds..."
Start-Sleep -Seconds $HoldSeconds
}
finally {
Write-Host "Disable ICS again..."
$items = Get-IcsItems
Disable-AllIcs $items
Write-Host ""
Write-Host "ICS pulse finished."
Write-Host "Now test TUN."
Pause
}
6 个帖子 - 5 位参与者