Script for new network devices

Hello,

I am new to scripting and am trying to create a script that will find new devices on the network and alert me. I thought I might try creating a script that looks through the DHCP leases for any expires-after time greater than a set amount of time. Then I would have these new leases emailed to myself telling me the mac address, ip, and hostname. I seem to be having trouble finding a way to use the expires-after property of the lease in a script. Specifically, returning that value to be compared against my set amount of time. Does anyone know how to do this?

If you have a separate device that you can ensure to always be online (essentially, a “server”), you can create an API program, and use the APIs “listen” command.

That way, as soon as there are new DHCP entries, your program will know, and it can then do whatever you make it to, including sending you an email.

Working with dates and times is a PITA in scripting.

Thanks for the reply. I’m not too familiar with creating API’s. Do you have anything I can reference?

At the API’s manual page, you can see a lot of clients for various languages at the bottom.

If you’re familiar with any of those programming languages, you can use its client. Personally, I know and can assist with PHP (and the “PHP #2” client in particular), but if you don’t know any PHP yourself, this is likely to be very difficult… even with my help. The most difficult part would be in installing PHP… and a mail server (so that you can send emails)… and configuring the two to work together… on your computer. After that, it should be relatively straightforward. PHP as a language itself is not that hard to learn.