$ipTxt = @"
1.1.1.1
2.2.2.2
3.3.3.3
"@
# 将 ip 文本拆分为数组
[string[]]$ips = $ipTxt.Split([char[]]"`r`n") | % { $_.Trim() } | ? { $_.Length -gt 0 }
0..19 | % {
# 代理地址及端口
$port = 50000 + $_ + 1
$proxyUrl = "http://10.1.1.118:$port"
# 使用代理发送请求到 IP 查询服务
$response = Invoke-WebRequest -Uri "https://api.ipify.org?format=json" -Proxy $proxyUrl -ProxyUseDefaultCredentials
# 解析响应内容(JSON 格式)
$ipInfo = $response.Content | ConvertFrom-Json
$checkIp = $ips[$_]
# 输出当前 IP 地址
# Write-Output "当前 IP 地址: $($ipInfo.ip), $checkIp"
$msg = "当前 $($ipInfo.ip), 期望 $checkIp"
if($ipInfo.ip -eq $checkIp){
Write-Host "$($_), IP 一致, $msg"
}
else{
Write-Host "$($_), IP 不一致, $msg" -ForegroundColor Red
}
}