pwsh 检测一批代理外网地址

检测代理是否正常

$ErrorActionPreference = "Stop"

# 获取代理地址 
function GetProxyIP([string]$proxyServer) {

    $ipInfoUrl = "https://ipinfo.io/ip"
    # $proxyServer = "http://10.10.2.103:1087"
    $proxyOptions = @{ Proxy = $proxyServer }

    try {

        $response = Invoke-WebRequest -Uri $ipInfoUrl -ProxyUseDefaultCredentials @proxyOptions -ErrorAction Stop

        if ($response.StatusCode -ne 200) {
            throw [System.ApplicationException]::new("错误:[$($response.StatusCode)]")
        }

        echo $response.Content

    }
    catch {
        echo $_.Exception.Message
    }

}

1001..1088 | % { "http://10.10.2.103:$_" } | % { GetProxyIP($_) }
上一篇
下一篇