mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
installer: improve region detection reliability using multiple APIs (#394)
This commit is contained in:
parent
1c057d93bd
commit
ed96432b79
@ -49,8 +49,20 @@ if ([string]::IsNullOrWhiteSpace($agenttag)) {
|
||||
}
|
||||
}
|
||||
#Region判断
|
||||
$ipapi= Invoke-RestMethod -Uri "https://api.myip.com/" -UserAgent "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1"
|
||||
$region=$ipapi.cc
|
||||
$ipapi = ""
|
||||
$region = "Unknown"
|
||||
foreach ($url in ("https://dash.cloudflare.com/cdn-cgi/trace","https://cf-ns.com/cdn-cgi/trace","https://1.0.0.1/cdn-cgi/trace")) {
|
||||
try {
|
||||
$ipapi = Invoke-RestMethod -Uri $url -TimeoutSec 5 -UseBasicParsing
|
||||
if ($ipapi -match "loc=(\w+)" ) {
|
||||
$region = $Matches[1]
|
||||
break
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Host "Error occurred while querying $url : $_"
|
||||
}
|
||||
}
|
||||
echo $ipapi
|
||||
if($region -ne "CN"){
|
||||
$download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"
|
||||
|
Loading…
Reference in New Issue
Block a user