Community discussions

MikroTik App
 
Josephny
Member
Member
Topic Author
Posts: 495
Joined: Tue Sep 20, 2022 12:11 am

Tracking new devices

Mon Nov 13, 2023 4:51 pm

I have been on a quest to keep track of the devices that connect to my systems.

Towards that end, I modified an existing script (very proud of myself) to email me the details of all new DHCP lease assignments:

/system
:local cdate [clock get date] 
:local yyyy  [:pick $cdate 0  4]
:local MM    [:pick $cdate 5  7]
:local dd    [:pick $cdate 8 10]

:local thistime [/system clock get time]
:local thishour [:pick $thistime 0 2]
:local thisminute [:pick $thistime 3 5]
:local thissecond [:pick $thistime 6 8]
:local identitydatetime "$[identity get name]_$yyyy-$MM-$dd_$thishour:$thisminute:$thissecond"
:local datetime "$yyyy-$MM-$dd_$thishour:$thisminute:$thissecond"
:local systemname "$[identity get name]"

:if ($leaseBound=1) do={

  :log info "testing after condition BOUND" }

:if  ([/ip dhcp-server lease find where dynamic mac-address=$leaseActMAC]!="") do={

  :log info "testing after condition DYNAMIC"}

:local recipient "joseph@xxxxx.com"

:if  (($leaseBound=1)  && ([/ip dhcp-server lease find where dynamic mac-address=$leaseActMAC]!="")) do={

    :log info "testing after conditions BOUND and DYNAMIC" 

    :tool e-mail send to=$recipient subject="$systemname DHCP Lease Assigned to $leaseActMAC" body="MAC address $leaseActMAC received IP address $leaseActIP with a hostname of $[/ip/dhcp-server/lease/get value-name=host-name [find where mac-address=$leaseActMAC]] from DHCP Server $leaseServerName on $datetime from $systemname"

    :log info "Sent DHCP alert for MAC $leaseActMAC"

}

Tiny problem is that the body of the message leaves a blank when the "host-name" does not exist.

But, the bigger problem is that the host-name doesn't exist and I want to know more about the newly connected device.

Has anyone figured out a way to run a scan on the new device (it will have an IP address) to get at least basic info about it (host name, DNS name, OS, services, etc.)?

Also, I would really like the data to be stored somewhere more easily saved and manipulated (email doesn't cut it for that).

I run a Home Assistant server with MQTT (Mosquitto) broker, but haven't been able to get the RouterOS<->HA-MQTT working. I went down the HA road because once new device info is in HA, I can utilize HA's other features such as letting me know when someone arrives, etc.

Thank you!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12014
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tracking new devices

Mon Nov 13, 2023 9:53 pm

If the device do not provide a host name, do not have a host name...

Who is online

Users browsing this forum: No registered users and 8 guests