Question : Monitor DNS MX records with a VBS script

Hi,

We want to monitor our MX records so if they get changed to something different we will get an alert.

The following scipt runs in order to monitor if any changes have happened for the MX recods but the problem that we have with the code is that we always get alertss since it uses nslookup and the output is always in a different order so the script will always thinks that there is a change and will trigger and alert.  

We just want to know about MX record changes but we don't look for changes on the order/position of the record.

Does anyone know a way to get to result that we want?

Thank you.
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

Answer : Monitor DNS MX records with a VBS script

Random Solutions  
 
programming4us programming4us