Skip to content

Commit ed96432

Browse files
author
MadDogOwner
authored
installer: improve region detection reliability using multiple APIs (#394)
1 parent 1c057d9 commit ed96432

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

script/install.ps1

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,20 @@ if ([string]::IsNullOrWhiteSpace($agenttag)) {
4949
}
5050
}
5151
#Region判断
52-
$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"
53-
$region=$ipapi.cc
52+
$ipapi = ""
53+
$region = "Unknown"
54+
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")) {
55+
try {
56+
$ipapi = Invoke-RestMethod -Uri $url -TimeoutSec 5 -UseBasicParsing
57+
if ($ipapi -match "loc=(\w+)" ) {
58+
$region = $Matches[1]
59+
break
60+
}
61+
}
62+
catch {
63+
Write-Host "Error occurred while querying $url : $_"
64+
}
65+
}
5466
echo $ipapi
5567
if($region -ne "CN"){
5668
$download = "https://github.com/$agentrepo/releases/download/$agenttag/$file"

0 commit comments

Comments
 (0)