DHCP Scripr error

Hi,

I have a DHCP vb script but gives an error can any one help me in this.

'**** DHCP Server Log Checking Script
'**** Copyright © 2005 Chris Pratt
'**** You may use this script free of charge but may not make any changes except to the variables to meet your needs
'**** without the permission of the author.
'****
'****
'**** The script is best set-up to run as a scheduled task. It can check for any event ID in the DHCP Server logs.
'**** It does not need to run on the DHCP server but you will need the full UNC path and the user that the script
'**** is set to run as will need rights to the servers log file areas.
'****
'**** The time interval is configurable and your scheduled task running time should be set to match that so areas of the
'**** logs don't go unchecked.

'Variables

strfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\inexchange1\c$\WINDOWS\system32\dhcp\dhcpsrvlog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@***.com" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject
objCDOMail.From = "sharath.reddy@***.com" 'E-mail from address (needs to be a valid address)
objCDOMail.From    =  "SYSTEM <INEXCHANGE1.***.co.uk>" ' E-mail from address (needs to be a valid address)

'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
set objCDOMail = CreateObject("CDONTS.NewMail")
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0
      
strline = objtextfile.readline

if instr(strline, "ID Date,Time,Description,IP Address,Host Name,MAC Address") then
            strline = objtextfile.readline
      else

      end if

if instr(strline, ",") then
            arrdhcprecord = split(strline, ",", 7)
            ceventid = arrdhcprecord(0)
            ceventdte = arrdhcprecord(1)
            ceventtime = arrdhcprecord(2)
            ceventdesc = arrdhcprecord(3)
            ceventip = arrdhcprecord(4)
            ceventhost = arrdhcprecord(5)
            ceventmac = arrdhcprecord(6)
      else

      End if
      i=i+1

findtime = datediff("n", ceventtime, strfindtime)

if findtime < intfindtime then
            posfind = posfind + 1
      else

      end if

if ceventid = streventid then
            posfind = posfind + 1
else

end if

if posfind = 2 then
            strBody = "===================" & vbCrLf
            strBody = strBody & " DHCP Server Alert" & vbCrLf
            strBody = strBody & "===================" & vbCrLf
            strBody = strBody & vbCrLf
            strBody = strBody & "Event ID: " & ceventid & vbCrLf
            strBody = strBody & "Date: " & ceventdte & vbCrLf
            strBody = strBody & "Time: " & ceventtime & vbCrLf
            strBody = strBody & "Desc: " & ceventdesc & vbCrLf
            strBody = strBody & "IP: " & ceventip & vbCrLf
            strBody = strBody & "Host: " & ceventhost & vbCrLf
            strBody = strBody & "Mac:" & ceventmac & vbCrLf
            objCDOMail.To      = strTo
            objCDOMail.Subject = strSubject
            objCDOMail.Body    = strBody
            objCDOMail.Send
      else

      end if

loop
objtextfile.close
Set objCDOMail = Nothing
LVL 11
bsharathAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mailtosinghsCommented:
Please tell us what is the error you are getting while executing this script
0
bsharathAuthor Commented:
---------------------------
Windows Script Host
---------------------------
Script:      C:\Documents and Settings\sharathr\Desktop\dhcpchecker_287\dhcpchecker.vbs
Line:      23
Char:      1
Error:      Object required: ''
Code:      800A01A8
Source:       Microsoft VBScript runtime error

---------------------------
OK  
---------------------------
0
mailtosinghsCommented:
Create another variable on line 23 and 24;

Line 23, and 24 to after line 30 where you have written "set objCDOMail = CreateObject("CDONTS.NewMail")"

this will help

this error was because you have tried to use the object "objCDOMail" before initializing it.
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

mailtosinghsCommented:
you can create variable to define to and from email address.

use these variables in the form.

objCDOMail.From = variable1
objCDOMail.From    = variable2
0
mailtosinghsCommented:
change this portion of script



'Variables

estrfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\inexchange1\c$\WINDOWS\system32\dhcp\dhcpsrvlog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@***.com" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject
objCDOMail.From = "sharath.reddy@***.com" 'E-mail from address (needs to be a valid address)
objCDOMail.From    =  "SYSTEM <INEXCHANGE1.***.co.uk>" ' E-mail from address (needs to be a valid address)

'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
set objCDOMail = CreateObject("CDONTS.NewMail")
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0




to




'Variables

strfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\inexchange1\c$\WINDOWS\system32\dhcp\dhcpsrvlog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@***.com" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject



'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
set objCDOMail = CreateObject("CDONTS.NewMail")
objCDOMail.From = strTo 'you have already defined the email-to field
objCDOMail.From    =  "SYSTEM <INEXCHANGE1.***.co.uk>" ' E-mail from address (neds to be a valid address)
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0



this should work :)
0
bsharathAuthor Commented:
mailtosinghs:
Now i get this error

C:\>cscript a.vbs
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.

C:\a.vbs(88, 3) (null): 0x80040108
0
mailtosinghsCommented:
this error is related to CDONTS

can you tell me what is on 88th line in that file...



0
bsharathAuthor Commented:
This is from the first line

strBody = strBody & "===================" & vbCrLf


Or started count from 'Variables

if posfind = 2 then
            strBody = "===================" & vbCrLf
            strBody = strBody & " DHCP Server Alert" & vbCrLf
            strBody = strBody & "===================" & vbCrLf
            strBody = strBody & vbCrLf
            strBody = strBody & "Event ID: " & ceventid & vbCrLf
            strBody = strBody & "Date: " & ceventdte & vbCrLf
            strBody = strBody & "Time: " & ceventtime & vbCrLf
            strBody = strBody & "Desc: " & ceventdesc & vbCrLf
            strBody = strBody & "IP: " & ceventip & vbCrLf
            strBody = strBody & "Host: " & ceventhost & vbCrLf
            strBody = strBody & "Mac:" & ceventmac & vbCrLf
            objCDOMail.To      = strTo
            objCDOMail.Subject = strSubject
            objCDOMail.Body    = strBody
            objCDOMail.Send
      else


Else is on the 80th line
0
mailtosinghsCommented:
please mail me this in .txt attachment to my user name here  at yahoo dot com

0
mailtosinghsCommented:
I dont know whether posting email address for attachments are allowed or not;
alternatively you can paste the entire script here again
0
bsharathAuthor Commented:
Here is the full script


'**** DHCP Server Log Checking Script
'**** Copyright © 2005 Chris Pratt
'**** You may use this script free of charge but may not make any changes except to the variables to meet your needs
'**** without the permission of the author.
'****
'****
'**** The script is best set-up to run as a scheduled task. It can check for any event ID in the DHCP Server logs.
'**** It does not need to run on the DHCP server but you will need the full UNC path and the user that the script
'**** is set to run as will need rights to the servers log file areas.
'****
'**** The time interval is configurable and your scheduled task running time should be set to match that so areas of the
'**** logs don't go unchecked.
'Variables

strfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\in-ads-srv02\c$\WINNT\system32\dhcp\DhcpSrvLog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject



'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
set objCDOMail = CreateObject("CDONTS.NewMail")
objCDOMail.From = strTo 'you have already defined the email-to field
objCDOMail.From    =  "SYSTEM <sharath.reddy@com>" ' E-mail from address (neds to be a valid address)
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0

      
strline = objtextfile.readline

if instr(strline, "ID Date,Time,Description,IP Address,Host Name,MAC Address") then
            strline = objtextfile.readline
      else

      end if

if instr(strline, ",") then
            arrdhcprecord = split(strline, ",", 7)
            ceventid = arrdhcprecord(0)
            ceventdte = arrdhcprecord(1)
            ceventtime = arrdhcprecord(2)
            ceventdesc = arrdhcprecord(3)
            ceventip = arrdhcprecord(4)
            ceventhost = arrdhcprecord(5)
            ceventmac = arrdhcprecord(6)
      else

      End if
      i=i+1

findtime = datediff("n", ceventtime, strfindtime)

if findtime < intfindtime then
            posfind = posfind + 1
      else

      end if

if ceventid = streventid then
            posfind = posfind + 1
else

end if

if posfind = 2 then
            strBody = "===================" & vbCrLf
            strBody = strBody & " DHCP Server Alert" & vbCrLf
            strBody = strBody & "===================" & vbCrLf
            strBody = strBody & vbCrLf
            strBody = strBody & "Event ID: " & ceventid & vbCrLf
            strBody = strBody & "Date: " & ceventdte & vbCrLf
            strBody = strBody & "Time: " & ceventtime & vbCrLf
            strBody = strBody & "Desc: " & ceventdesc & vbCrLf
            strBody = strBody & "IP: " & ceventip & vbCrLf
            strBody = strBody & "Host: " & ceventhost & vbCrLf
            strBody = strBody & "Mac:" & ceventmac & vbCrLf
            objCDOMail.To      = strTo
            objCDOMail.Subject = strSubject
            objCDOMail.Body    = strBody
            objCDOMail.Send
      else

      end if

loop
objtextfile.close
Set objCDOMail = Nothing
0
mailtosinghsCommented:
Use the modified script. I have moved set objcdomail.... to inside the while loop



'**** DHCP Server Log Checking Script
'**** Copyright © 2005 Chris Pratt
'**** You may use this script free of charge but may not make any changes except to the variables to meet your needs
'**** without the permission of the author.
'****
'****
'**** The script is best set-up to run as a scheduled task. It can check for any event ID in the DHCP Server logs.
'**** It does not need to run on the DHCP server but you will need the full UNC path and the user that the script
'**** is set to run as will need rights to the servers log file areas.
'****
'**** The time interval is configurable and your scheduled task running time should be set to match that so areas of the
'**** logs don't go unchecked.
'Variables

strfindtime = dateadd("n", -30, Time)           ' Change this figure (-30) to set interval between checking (in minutes)
intfindtime = 30 ' Change this value to match the one above
strtoday = (WeekdayName(Weekday(Date),true))
strlogfile = "\\in-ads-srv02\c$\WINNT\system32\dhcp\DhcpSrvLog." & strtoday    ' Change the locations to match that of your DHCP Server
streventid = "10"    ' Change to meet what event you want to check for - See the beginning of a log to see a definition list of the Event ID's
strTo = "sharath.reddy@isc.com" ' E-mail address TO
strSubject = "DHCP Server Alert" ' E-mail Subject



'Leave the rest of the script

Dim strTo, strSubject, strBody, i
Dim objCDOMail
const forreading = 1
set objfso = createobject("Scripting.filesystemobject")
set objtextfile = objfso.opentextfile(strlogfile, forreading)
do while objtextfile.atendofstream <> True
ceventid = ""
posfind = 0

     
strline = objtextfile.readline

if instr(strline, "ID Date,Time,Description,IP Address,Host Name,MAC Address") then
            strline = objtextfile.readline
      else

      end if

if instr(strline, ",") then
            arrdhcprecord = split(strline, ",", 7)
            ceventid = arrdhcprecord(0)
            ceventdte = arrdhcprecord(1)
            ceventtime = arrdhcprecord(2)
            ceventdesc = arrdhcprecord(3)
            ceventip = arrdhcprecord(4)
            ceventhost = arrdhcprecord(5)
            ceventmac = arrdhcprecord(6)
      else

      End if
      i=i+1

findtime = datediff("n", ceventtime, strfindtime)

if findtime < intfindtime then
            posfind = posfind + 1
      else

      end if

if ceventid = streventid then
            posfind = posfind + 1
else

end if

if posfind = 2 then
            strBody = "===================" & vbCrLf
            strBody = strBody & " DHCP Server Alert" & vbCrLf
            strBody = strBody & "===================" & vbCrLf
            strBody = strBody & vbCrLf
            strBody = strBody & "Event ID: " & ceventid & vbCrLf
            strBody = strBody & "Date: " & ceventdte & vbCrLf
            strBody = strBody & "Time: " & ceventtime & vbCrLf
            strBody = strBody & "Desc: " & ceventdesc & vbCrLf
            strBody = strBody & "IP: " & ceventip & vbCrLf
            strBody = strBody & "Host: " & ceventhost & vbCrLf
            strBody = strBody & "Mac:" & ceventmac & vbCrLf
            set objCDOMail = CreateObject("CDONTS.NewMail")
            objCDOMail.From    =  "SYSTEM <sharath.reddy@i.com>" ' E-mail from address (neds to be a valid address)
            objCDOMail.To      = strTo
            objCDOMail.Subject = strSubject
            objCDOMail.Body    = strBody
            objCDOMail.Send
            Set objCDOMail = Nothing
      else

      end if

loop
objtextfile.close
0
bsharathAuthor Commented:
Hi

Some thing went on it came out without any error but how do i find it is working.
Until you have understood can you tell me what this script does
THX
Sharath
0
mailtosinghsCommented:
if you wnat to know that it went into the loop or not you can insert the line

WScript.Echo "some text"

and run the script again, you should see the echo message while the script in loop.

if this was not what you need, please specify the qn again clearly
0
mailtosinghsCommented:
please insert above line before the

objCDOMail.Send
0
bsharathAuthor Commented:
I got a box containing "Sometext"

But where will i get the result.I now that this is correct but where can i see the result.

THX
For replying so patiently.

THX
Sharath
0
mailtosinghsCommented:
You will get the result in the email address mentioned in the script which is sharath.reddy@isc.com here.

For a successful email, you need direct internet connectivity of the system where this script is running, or you have to setup intranet properly
0
bsharathAuthor Commented:
This mail will come when ever a error is encountered on the server or ?? Is there any wany i can genetrate a faulse error or through the script can we send a test mail.
0
mailtosinghsCommented:
this will send a mail if you have eventid 10 in today's dhcp log in past 30 min.

if you want to generate an email do this:.....

open
\\in-ads-srv02\c$\WINNT\system32\dhcp\DhcpSrvLog." & strtoday
for this go to the folder "\\in-ads-srv02\c$\WINNT\system32\dhcp\"
open today's logfile dhcpsrvlog.mon if day is monday
you will find following texts after scrolling some lines


ID Date,Time,Description,IP Address,Host Name,MAC Address
00,04/19/99,12:43:06,Started,,,
60,04/19/99,12:43:21,No DC is DS Enabled,,MYDOMAIN,
63,04/19/99,12:43:28,Restarting rogue detection,,,
01,04/19/99,13:11:13,Stopped,,,
00,04/19/99,12:43:06,Started,,,
55,04/19/99,12:43:54,Authorized(servicing),,MYDOMAIN,

change 10 in following line of code to 00 in the script file.
streventid = "10"


stop and restart the dhcp service.
rerun the script


please remove the line
WScript.Echo "some text"
or change this to a comment
0
mailtosinghsCommented:
the log text i have posted is a sample, you may find different texts but in same format
0
bsharathAuthor Commented:
In the log file what should i change
0
bsharathAuthor Commented:
I have changed all 10 to 00 the restart the DHCP service the ran the script but did not receive any mails

THX
Sharath
0
mailtosinghsCommented:
CDONTS is not able to send mail to the the recipient.

CDONTS is older version and not recommended. CDOSYS is now used in place of CDONTS and is more reliable and configurable.
you should use CDOSYS to send mail using an SMTP server in your intranet where the ip of your system (where the script is executing) is  allowed to relay mails.

for cdosys example search cdosys examples in google.


http://kb.webecs.com/Article.aspx?id=10169&cNode=7U0G0Q
http://www.pacificonline.com/SmarterTicket/Customer/KBArticle.aspx?articleid=36&KBSearchID=16275
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bsharathAuthor Commented:
Hi,

I have no clue on what you said now sorry to say i dont know anything about scripting.Please help me in this regard.

THX
Sharath
0
bsharathAuthor Commented:
Thanks for the support.Even though i havent got the solution i am closing the question
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Legacy OS

From novice to tech pro — start learning today.