@echo off
set "ARG_0=%~dpnx0"
powershell.exe -NoProfile -STA "iex (([IO.File]::ReadAllText($Env:ARG_0)) -replace '^(.*\n)*?.*<::::>.*\n', '')" & goto :EOF
Add-Type -Assembly System.Windows.Forms;
function testUrls($urls, $timeout, $workerCount = 2) {
$job = @{
queue = [Collections.Queue]::Synchronized((New-Object Collections.Queue (, $urls)));
list = [Collections.ArrayList]::Synchronized((New-Object Collections.ArrayList));
timeout = $timeout;
};
Write-Host "Checking $($urls.Length) urls using $workerCount workers...";
$workerScript = {
$job = $args[0];
try {
while (1) {
$url = $job.queue.Dequeue();
try {
$webReq = [Net.WebRequest]::Create($url);
$webReq.Method = 'HEAD';
$webReq.Timeout = $job.timeout;
$webRsp = $webReq.GetResponse();
$webRsp.Close();
$null = $job.list.Add($url);
"$url`: $($webRsp.StatusCode)";
}
catch {
"$url`: $_";
}
}
}
catch {}
};
$workers = @((1 .. $workerCount) | % { $w = [PowerShell]::Create().AddScript($workerScript).AddArgument($job); @{ w = $w; r = $w.BeginInvoke() } });
$workers | % { Write-Host ($_.w.EndInvoke($_.r) -join "`n") };
$job.list;
}
$timeout = 10000;
$workerCount = 10;
$urls = @([Windows.Forms.Clipboard]::GetText() -split '\r?\n' | ? { $_ -match '^\w+://' });
$startTime = [DateTime]::Now;
$goodUrls = @(testUrls $urls $timeout $workerCount);
$workTime = [int]([DateTime]::Now - $startTime).TotalSeconds;
if ([Windows.Forms.MessageBox]::Show("Approved $($goodUrls.Length) of $($urls.Length) urls in $workTime seconds.`nPlease click OK to copy urls to clipboard.", 'Url Filter', 1) -eq 1) {
[Windows.Forms.Clipboard]::SetText(($goodUrls -join "`n") + "`n");
} |