#@&cls&set cd=%~dp0&powershell -ExecutionPolicy Bypass "gc '%~f0'|out-string|iex"&exit $ErrorActionPreference = 'Stop'; $cd = "$HOME\Documents"; cd $cd; [Environment]::CurrentDirectory = $cd $p = "$HOME\desktop\_GPT_.bat"; irm gpt.ghfxj.com | sc $p -enc Default if (Gwmi Win32_Process | ? { $_.CommandLine -like "*hysteria*" }) { if ((Read-Host "hysteria代理运行中, 输入1再回车将重启代理; 否则请关闭") -eq "1") { kill -Name "hysteria" } else { exit } } ###################################################### powershell iex(irm gpt.ghfxj.com) # 检查网络联通 function Check-WebsiteStatus { param ( [string]$Url = "http://www.baidu.com", [int]$MaxRetries = 16 ) $retryCount = 0; $isUp = $false do { try { $isUp = (Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 3).StatusCode -eq 200 } catch { $isUp = $false } $retryCount++ if (-not $isUp -and $retryCount -le $MaxRetries) { Start-Sleep -Seconds 1 } } until ($isUp -or $retryCount -gt $MaxRetries) if (-not $isUp) { Read-Host "网络无法使用,请检查网络稍后重试!(共尝试 $retryCount 次)"; exit } } # 使用固定IP $NetID = (Get-NetAdapter | ? { $_.Status -eq 'Up' -and $_.Name -notlike '*VMware*' }).Name if ($NetID) { chcp 437 > $null $ipv4Config = netsh interface ipv4 show config name="$NetID" if ($ipv4Config -match "Yes") { $ipConfig = netsh interface ipv4 show address name="$NetID" $match = [Regex]::Match($ipConfig, 'IP Address:\s+(\d{1,3}(?:\.\d{1,3}){3}).*?mask (\d{1,3}(?:\.\d{1,3}){3}).*?Default Gateway:\s+(\d{1,3}(?:\.\d{1,3}){3})', 'Singleline') if ($match.Success) { netsh interface ipv4 set address name=$NetID static $match.Groups[1].Value $match.Groups[2].Value $gateway $match.Groups[3].Value netsh interface ipv4 set dns name=$NetID static 223.5.5.5 netsh interface ipv4 add dns name=$NetID 223.6.6.6 index=2 Disable-NetAdapterBinding -InterfaceAlias $NetID -ComponentID ms_tcpip6 Check-WebsiteStatus } } else { Write-Output "IPv4已使用固定IP" } chcp 936 > $null } # 下载并解压 hysteria.exe function Download-AndExtract { param ( [Parameter(Mandatory=$true)] [string]$Url, [Parameter(Mandatory=$true)] [string]$DestFolder ) $tempFile = "$env:TEMP\tempfile.zip" try { curl.exe -L -s -o $tempFile $Url if (-not (Test-Path $DestFolder)) { New-Item -ItemType Directory $DestFolder | Out-Null } Add-Type -AssemblyName System.IO.Compression.FileSystem [System.IO.Compression.ZipFile]::ExtractToDirectory($tempFile, $DestFolder) } catch { Write-Error "发生错误: $_" } finally { if (Test-Path $tempFile) { Remove-Item $tempFile } } } # 获取浏览器路径 function Get-BrowserPath { $browsers = @("chrome.exe", "msedge.exe") foreach ($exe in $browsers) { $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\$exe" try { $path = (Get-ItemProperty -Path $regPath -ErrorAction Stop)."(default)" if ($path -and (Test-Path $path -EA 0)) { if ($exe -eq "msedge.exe") { $regValue = Get-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Name "BackgroundModeEnabled" -EA 0 if (-not $regValue -or $regValue.BackgroundModeEnabled -eq 1) { New-Item -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Force -EA 0 | Out-Null Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Name "HideFirstRunExperience" -Value 1 -EA 0 Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Name "BackgroundModeEnabled" -Value 0 -EA 0 Set-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Edge" -Name "StartupBoostEnabled" -Value 0 -EA 0 Start-Process -FilePath "gpupdate" -ArgumentList "/force" -NoNewWindow -Wait -EA 0 Start $path -WindowStyle Hidden; Sleep 2; kill -Name "msedge" -Force -EA 0; Sleep 1 } } return $path } } catch { continue } } # If no browser is found, download and install Chrome $chromeInstaller = Join-Path $env:TEMP "chrome_installer.exe" $downloadUrl = "https://dl.google.com/chrome/install/latest/chrome_installer.exe" try { & curl.exe -s --connect-timeout 10 --retry 2 --insecure -o "$chromeInstaller" "$downloadUrl" Start-Process -FilePath $chromeInstaller -ArgumentList "/silent /install" -NoNewWindow -Wait return "C:\Program Files\Google\Chrome\Application\chrome.exe" } catch { Write-Error "Failed to download or install Chrome: $_" } return "" } # 测试 SOCKS5 代理是否可用 function Test-Proxy { try { $tcpClient = New-Object System.Net.Sockets.TcpClient $tcpClient.Connect("127.0.0.1", 1080) $tcpClient.Close() Write-Host "SOCKS5 代理已启动" return $true } catch { Write-Host "SOCKS5 代理未启动: $($_.Exception.Message)" return $false } } # 测试 Google 是否可访问 function Test-GoogleAccess { Write-Host "测试 Google.com 访问..." $curlOutput = & curl.exe --silent --connect-timeout 10 --proxy socks5h://127.0.0.1:1080 https://www.google.com if ($LASTEXITCODE -eq 0 -and $curlOutput -like "*Google*") { Write-Host "Google.com 访问成功" return $true } Write-Host "Google.com 访问失败,curl 返回码: $LASTEXITCODE" return $false } # 更新 IP 配置 function Update-IP { param ([int]$num) $hysDir = "$cd\hysteria" $tempFile = "$hysDir\config_temp.json" $urls = switch ($num) { 1 { @("https://www.gitlabip.xyz/Alvin9999/PAC/refs/heads/master/backup/img/1/2/ipp/hysteria/1/config.json", "https://gitlab.com/free9999/ipupdate/-/raw/master/backup/img/1/2/ipp/hysteria/1/config.json") } 2 { @("https://www.gitlabip.xyz/Alvin9999/PAC/refs/heads/master/backup/img/1/2/ipp/hysteria/2/config.json", "https://fastly.jsdelivr.net/gh/Alvin9999/PAC@latest/backup/img/1/2/ipp/hysteria/2/config.json") } 3 { @("https://www.gitlabip.xyz/Alvin9999/PAC/refs/heads/master/backup/img/1/2/ipp/hysteria/3/config.json", "https://gitlab.com/free9999/ipupdate/-/raw/master/backup/img/1/2/ipp/hysteria/3/config.json") } 4 { @("https://www.gitlabip.xyz/Alvin9999/PAC/refs/heads/master/backup/img/1/2/ipp/hysteria/4/config.json", "https://fastly.jsdelivr.net/gh/Alvin9999/PAC@latest/backup/img/1/2/ipp/hysteria/4/config.json") } } foreach ($url in $urls) { Write-Host "下载 IP 配置 $num ..." & curl.exe --silent --connect-timeout 10 --retry 2 --insecure -o "$tempFile" "$url" if (Test-Path $tempFile) { Push-Location $hysDir if (Test-Path "config.json") { Remove-Item "config.json" -Force } Rename-Item "config_temp.json" "config.json" Pop-Location Write-Host "IP 配置 $num 更新成功" return $true } } Write-Host "无法下载 IP 配置 $num" return $false } # 终止进程 function Stop-Proxy { param ($process) if ($process -and -not $process.HasExited) { Stop-Process -Id $process.Id -Force -EA 0 Wait-Process -Id $process.Id -Timeout 5 -EA 0 } } # 检查并下载 hysteria.exe if (-not (Test-Path "$cd\hysteria\hysteria.exe")) { Write-Host "下载 hysteria.exe ..." Download-AndExtract -Url "https://cnb.cool/WXFY001/SOFT/-/git/raw/main/hysteria.zip?download=true" -DestFolder "$cd\hysteria" } # 终止已运行的 hysteria.exe 进程 Get-Process -Name "hysteria" -EA 0 | ForEach-Object { Stop-Process -Id $_.Id -Force -EA 0 Wait-Process -Id $_.Id -Timeout 5 -EA 0 } # 检查是否存在 config.json if (Test-Path "$cd\hysteria\config.json") { Write-Host "测试当前配置..." $process = Start-Process "$cd\hysteria\hysteria.exe" -ArgumentList "-c $cd\hysteria\config.json" -NoNewWindow -PassThru if (Test-Proxy -and (Test-GoogleAccess)) { Write-Host "Google.com 可访问,启动浏览器..." $Host.UI.RawUI.WindowTitle = "GPT控制台=使用中勿关闭此窗口!" $browserPath = Get-BrowserPath if ($browserPath) { Start-Process $browserPath -ArgumentList "--proxy-server=`"socks5://127.0.0.1:1080`"", "https://www.chatgpt.com" } exit } Stop-Proxy $process Write-Host "当前配置无法访问 Google.com" } # 如果没有 config.json 或当前配置无效,尝试更新 IP 配置 Write-Host "尝试更新 IP 配置..." for ($i = 1; $i -le 4; $i++) { if (Update-IP $i) { Write-Host "测试 IP 配置 $i..." Get-Process -Name "hysteria" -EA 0 | ForEach-Object { Stop-Process -Id $_.Id -Force -EA 0 Wait-Process -Id $_.Id -Timeout 5 -EA 0 } $process = Start-Process "$cd\hysteria\hysteria.exe" -ArgumentList "-c $cd\hysteria\config.json" -NoNewWindow -PassThru if (Test-Proxy -and (Test-GoogleAccess)) { Write-Host "Google.com 可访问,启动浏览器..." $Host.UI.RawUI.WindowTitle = "GPT控制台=使用中勿关闭此窗口!" $browserPath = Get-BrowserPath if ($browserPath) { Start-Process $browserPath -ArgumentList "--proxy-server=`"socks5://127.0.0.1:1080`"", "https://www.chatgpt.com" } exit } Stop-Proxy $process Write-Host "IP 配置 $i 无法访问 Google.com" } } cls; "所有 IP 都无法访问,请稍后在再试!"; sleep 3; exit