0

I'm trying to automate this task of checking sites SPF records and was wondering if anyone have got around this. I need to be able to go to the site and then type in a domain name eg. stuff.co.nz and get then click on Get SPF record and output the result to a text file.

Below is what I've attempted to do. Any help would be appreciated.

$ie = New-Object -Com InternetExplorer.Application

$ie.Visible=$true

$ie.navigate("http://www.kitterman.com/spf/validate.html")

$ie.Document.getElementsByName("domain").value="stuff.co.nz"

$ie.Document.GetElementsByvalue("Get SPF Record (if any)").click()
Syphirint
  • 1,021
  • 2
  • 13
  • 24
riftha
  • 107
  • 1
  • 1
  • 6
  • Is it really mandatory to use IE to do this? Why can't you just send a http request and capture the output? Please refer to http://stackoverflow.com/questions/17325293/invoke-webrequest-post-with-parameters for more information. –  Aug 24 '16 at 03:55
  • If you really want to do this using IE, please refer http://stackoverflow.com/questions/17049203/powershell-download-or-save-source-code-for-whole-ie-page to save the whole page. –  Aug 24 '16 at 04:12

2 Answers2

0

I think it's not necessary to launch IE to accomplish this.

The below script should make a HTTP post request to get SPF records and saves the output to a text file.

$postParams = @{domain='stuff.co.nz';serial='fred12'}
Invoke-WebRequest -Uri http://www.kitterman.com/getspf2.py -Method POST -Body $postParams -OutFile output.txt

If you would still like to use IE, you just need to save the whole page. Refer to this post.

Community
  • 1
  • 1
0

If all you're clicking is 'get SPF record' (and not doing the validity tests), then you're using PowerShell to automate IE to lookup something in DNS to connect to a website to scrape the page and enter a hostname so the remote server can lookup something in DNS so you can scrape it out of IE.

Skip all that and lookup the SPF record directly, it's a TXT record in DNS which starts 'v=spf1', so:

(Resolve-DnsName -Type TXT stuff.co.nz).strings -match '^v=spf1'
TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87