Question : VBS Script to monitor MX record changes

Hi,

I was wondering if there is any way to monitor for MX records changes. We are not managing our DNS zone and more than once the records have been changed and we haven't been informed until the mail queues are are big or someone calls.

Could this be scripted in a way that the script will check out there and find for the following records if they are different to what we I have specified below then we will get an email notification.

domain.com    MX preference = 8, mail exchanger = domain.com.s5b2.pts.com
domain.com    MX preference = 2, mail exchanger = domain.com.s5a1.pts.com
domain.com    MX preference = 4, mail exchanger = domain.com.s5a2.pts.com
domain.com    MX preference = 6, mail exchanger = domain.com.s5b1.pts.com

Could somone help us out to script this out?

Thank you

Answer : VBS Script to monitor MX record changes

Its quite alright, I do make mistakes sometimes.  And thanks to your bringing my attention back to this question, it actually made me test my script to find that there was a problem in my syntax.  Instead of there being 5 spaces between the domain name at the beginning and the "MX preference" part, it is a tab.  The way it was would have always thought there was a change.

 I corrected it and also added the option to change the DNS server that you want to query.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
strEmailTo="[email protected]"
strEmailFrom="DNS monitor"
strDomain="yourdomain.com"
strDNSServer="4.2.2.2"
strSMTPServer="yoursmtpserver"
iSMTPPort=25
Do
	Set objShell = CreateObject("WScript.Shell")
	Set objNSLookup = objShell.Exec("nslookup -q=MX "&strDomain&" "&strDNSServer)
	Set objStdOut = objNSLookup.StdOut
	strOutput = objStdOut.ReadAll
	
	bChanged=False
	If Instr(strOutput,strDomain&vbTab&"MX preference = 8, mail exchanger = "&strDomain&".s5b2.pts.com")=0 then bChanged=True
	If Instr(strOutput,strDomain&vbTab&"MX preference = 2, mail exchanger = "&strDomain&".s5a1.pts.com")=0 then bChanged=True
	If Instr(strOutput,strDomain&vbTab&"MX preference = 4, mail exchanger = "&strDomain&".s5a2.pts.com")=0 then bChanged=True
	If Instr(strOutput,strDomain&vbTab&"MX preference = 6, mail exchanger = "&strDomain&".s5b1.pts.com")=0 then bChanged=True

	If bChanged=True then
		Set objEmail = CreateObject("CDO.Message")
		objEmail.From = strEmailFrom
		objEmail.To = strEmailTo
		objEmail.Subject = "DNS changed"
		objEmail.Textbody = strOutput
		objEmail.Configuration.Fields.Item _
		    ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
		objEmail.Configuration.Fields.Item _
		    ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strSMTPServer
		objEmail.Configuration.Fields.Item _
		    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = iSMTPPort
		objEmail.Configuration.Fields.Update
		objEmail.Send
		wscript.quit
	End If
	wscript.sleep 60000
Loop
Random Solutions  
 
programming4us programming4us