mirror of
https://github.com/nezhahq/nezha.git
synced 2025-02-02 01:28:13 -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判断
|
#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"
|
$ipapi = ""
|
||||||
$region=$ipapi.cc
|
$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
|
echo $ipapi
|
||||||
if($region -ne "CN"){
|
if($region -ne "CN"){
|
||||||
$download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"
|
$download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"
|
||||||
|
Loading…
Reference in New Issue
Block a user