3

I have a script I'm using to loop through a bunch of domains and get dates from whois.exe. This works line-by-line, but when run as a script, it'll freeze. Here is where it gets stuck:

ForEach ($domain in $domains)
{
    $domainname = $domain.Name

    Write-Host "Processing $domainname..."

    # WhoIsCL responds with different information depending on if it's a .org or something else. 
    if($domainname -like "*.org" -and $domainname)
    {
        $date = .\WhoIs.exe -v "$domainname" | Select-String -Pattern "Registry Expiry Date: " -AllMatches
        Write-Host "Domain is a .org" -ForegroundColor "Yellow"

When I CTRL+C to cancel the command, I can verify that $domain is the correct variable. I can then write this:

if($domainname -like "*.org" -and $domainname)
{
    "Test"  
}

... and "Test" appears in the command line. I then run:

$date = .\WhoIs.exe -v "$domainname" | Select-String -Pattern "Registry Expiry Date: " -AllMatches

Upon checking the date, it comes out right and I get the appropriate date. Given it freezes right as it says "Processing $domainname..." and right before "Domain is a .org", I can only assume WhoIs.exe is freezing. So, why does this happen as the script is being run, but not directly from the Powershell window?

Lastly, I did a final test by simply copying and pasting the entire script into a Powershell window (which is just silly, but it appears to function) and get the same result. It freezes at whois.exe.

My best guess is that whois.exe needs to be run differently to be reliable in Powershell in my for-loop. However, I don't seem to have a way to test using it in a Start-Process and get string output.

Anyways, advise would be great. I've definitely hit a wall.

Thanks!

jackmusick
  • 311
  • 2
  • 7

1 Answers1

4

If your script is running through lots of domains, it could be that you're being throttled. Here is a quote from the Nominet AUP:

The maximum query rate is 5 queries per second with a maximum of 1,000 queries per rolling 24 hours. If you exceed the query limits a block will be imposed. For further details regarding blocks please see the detailed instructions for use page. These limits are not per IP address, they are per user.

http://registrars.nominet.org.uk/registration-and-domain-management/acceptable-use-policy

Different registrars may behave differently, but I'd expect some sort of rate limit. This would explain why a script (with high volume) behaves differently to ad-hoc manual lookups.


Proposed solution from the comments below is to add Start-Sleep -Seconds 1 to the loop between each Whois lookup.

Charlie Joynt
  • 4,411
  • 1
  • 24
  • 46
  • 2
    This looks extremely likely. Adding a `Start-Sleep -Sec 1` inside the loop will probably resolve the issue. If it does you can play with the timing to find something optimal. – TheMadTechnician Apr 29 '16 at 22:46
  • This was indeed the case. I didn't think it was the case since it was only affecting .org domains and a sleep timer did not work -- I tried that before I saw this put up in my notifications. To resolve my issue, I ended up using a paid WhoIs service which didn't have a rate limit and now everything is working as intended. I'm going to do some more tests against the WhoIs.exe application with a sleep timer, but I think ultimately, that's not going to be a solution I rely on. Thank you! – jackmusick Apr 30 '16 at 20:44