Guest User

Untitled

a guest
Mar 14th, 2012
484
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Hash tables to store results of previous MX checks
  2. $positiveMX = @{}
  3. $negativeMX = @{}
  4.  
  5. #Adding this just so you have some visual for how far along you are.  It will slow it down slightly, so if you're
  6. #purely worried about speed (or not running it interactively), remove this and the 4 $count lines in the loop
  7. $count = 0
  8.  
  9. #Prep the CSV with headers
  10. "domain,address" | set-content c:\temp\log.txt
  11.  
  12. #Read the file.  Using pipelining to avoid storing the entire thing in memory
  13. get-content "C:\temp\email.txt" | foreach {
  14.     $count++
  15.     if ($count%500 -eq 0) {
  16.         write-host $count -foregroundcolor black -backgroundcolor white
  17.     }
  18.  
  19.  
  20.     $domain= $_.split("@")[1]
  21.  
  22.     #If the MX record passed the test previously, go ahead and pass it through for writing
  23.     if ($positiveMX.ContainsKey($domain)) {
  24.         "$domain,$_"
  25.     #Else, check to see if we found it before but disliked it, and if so do nothing
  26.     } elseif ($negativeMX.ContainsKey($domain)) {
  27.     #Else, haven't seen it before, need to do an MX Lookup
  28.     } else {
  29.         #Note that I changed this from '*yahoo.com' to '*yahoo*', since I tried using yahoo.com to test, and that ended with yahoodns.net.
  30.         #If you know for sure that you want *yahoo.com, change it back
  31.         $mx = nslookup -type=mx $domain | where {$_ -like '*yahoo*'}
  32.  
  33.         #Found it, adding it to the positive list and passing through for writing
  34.         if($mx){
  35.             "$domain,$_"
  36.             $positiveMX.Add($domain,"")
  37.         #Didn't find it, adding it to the bad list
  38.         } else {
  39.             $negativeMX.Add($domain,"")
  40.         }
  41.     }
  42. } | add-content c:\temp\log.txt
Advertisement
Add Comment
Please, Sign In to add comment