Announcement

Collapse
No announcement yet.

Notification when DHCP lease is given

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Notification when DHCP lease is given

    Hi all

    Does anyone know of a way to be notified when a new DHCP lease is given out? Does it log in the event log?

    Many thanks
    Server 2000 MCP
    Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

    ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

  • #2
    no events in the eventlog as far as i know...
    but it looks like you can script it.... altough i never script something like tihs...

    DHCP callout Table:

    http://msdn.microsoft.com/library/de...lout_table.asp

    and to send a mail with a script see this..
    http://www.petri.com/send_mail_from_script.htm

    i'm very curieus how you could script something like this.. i haven't the time for it right now, to help you further...

    hopefully this links can help you out..
    Marcel
    Technical Consultant
    Netherlands
    http://www.phetios.com
    http://blog.nessus.nl

    MCITP(EA, SA), MCSA/E 2003:Security, CCNA, SNAF, DCUCI, CCSA/E/E+ (R60), VCP4/5, NCDA, NCIE - SAN, NCIE - BR, EMCPE
    "No matter how secure, there is always the human factor."

    "Enjoy life today, tomorrow may never come."
    "If you're going through hell, keep going. ~Winston Churchill"

    Comment


    • #3
      Looks promising but i think im a little out of my league for scripting here. Any help would be very appreciated!!
      Server 2000 MCP
      Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

      ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

      Comment


      • #4
        Re: Notification when DHCP lease is given

        Originally posted by tonyyeb
        Hi all

        Does anyone know of a way to be notified when a new DHCP lease is given out? Does it log in the event log?

        Many thanks
        WHY?

        (Curiosity killed the cat.)
        1 1 was a racehorse.
        2 2 was 1 2.
        1 1 1 1 race 1 day,
        2 2 1 1 2

        Comment


        • #5
          Well yesterday i noticed a new computer on the network... it turned out to be a student that had brought his own laptop into college. Now thankfully he couldn't do much but thats not the point. DHCP gave him an IP address and it was lucky i spotted it. He could have had a virus etc... or something that may have caused an issue.

          Ive spotted that it creates a daily text log in c:\winnt\system32\dhcp\ so i may write something that probes that every 5 mins and compares it to AD's list of computers joined to the domain.
          Server 2000 MCP
          Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

          ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

          Comment


          • #6
            Ok here is my code at the moment:

            Code:
            const forreading = 1
            set objfso = createobject("Scripting.filesystemobject")
            set objtextfile = objfso.opentextfile("c:\dhcpsrvlog.sat", forreading)
            do while objtextfile.atendofstream <> True
            ceventid = ""
            	if instr(objtextfile.readline, ",") then
            		arrdhcprecord = split(objtextfile.readline, ",", 7)
            		ceventid = arrdhcprecord(0)
            		ceventdte = arrdhcprecord(1)
            		ceventtime = arrdhcprecord(2)
            		ceventdesc = arrdhcprecord(3)
            		ceventip = arrdhcprecord(4)
            		ceventhost = arrdhcprecord(5)
            		ceventmac = arrdhcprecord(6)
            	End if
            	i=i+1
            
            if ceventid = "10" then
            	wscript.echo " ID: " & ceventid & " Date: " & ceventdte & " Time: " & ceventtime & " Desc: " & ceventdesc & " IP: " & ceventip & " Host: " & ceventhost & " Mac:" & ceventmac
            else 
            
            end if
            
            loop
            objtextfile.close
            I have a problem where it seems to be skipping a line and i think it is here:

            Code:
            if instr(objtextfile.readline, ",") then
            		arrdhcprecord = split(objtextfile.readline, ",", 7)
            But i dont know how to re-do this bit?
            Server 2000 MCP
            Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

            ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

            Comment


            • #7
              Just thought i'd update those following this thread. I have solved my line skip problem with the following:

              Code:
              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
              I have also set the script to check the previous x minutes of the log. The script will also load todays log instead of having to specify it. Now i just need to quickly add the e-mail part of the script and tidy it up with some comments and i hope to post the completed code.
              Server 2000 MCP
              Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

              ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

              Comment


              • #8
                Well here it is, finally completed. Any comments, bug reports etc.. then please post them here. Thanks.

                Code:
                '**** 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 = "\\london\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 = "[email protected]" ' E-mail address TO
                strSubject = "DHCP Server Alert" ' E-mail Subject
                objCDOMail.From = "[email protected]" 'E-mail from address (needs to be a valid address)
                objCDOMail.From    =  "SYSTEM <[email protected]>" ' 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
                Attached Files
                Server 2000 MCP
                Development: ASP, ASP.Net, PHP, VB, VB.Net, MySQL, MSSQL - Check out my blog http://tonyyeb.blogspot.com

                ** Remember to give credit where credit is due and leave reputation points sigpic where appropriate **

                Comment


                • #9
                  Re: Notification when DHCP lease is given

                  I am using v2.1 of this script from this forum. I fixed the "endif" should be "end if" on line 31, but am now getting an error on line 67:

                  Line: 67
                  Char: 3
                  Error: Subscript out of range '[number: 6]'
                  Code: 800A0009

                  What's missing? I am running it from a command prompt on my Exchange 2000 box (Windows 2000 Server). My DHCP server is also a Windows 2000 Server machine.

                  Thanks
                  -Randy-
                  Last edited by randy_randy; 20th December 2006, 18:03.

                  Comment

                  Working...
                  X