Created
July 6, 2023 00:47
-
-
Save henriquesebastiao/2958f14ee09337c99136573947829ebc to your computer and use it in GitHub Desktop.
Script para dispositivos Mikrotik que realiza o envio de uma mensagem para o Telegram sempre que um novo IP for concedido por DHCP. Também cria um controle de banda para esse IP.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| :local custLeaseHost; | |
| # Obtém o hostname do dispositivo | |
| :set custLeaseHost [/ip dhcp-server lease get value-name=host-name [/ip dhcp-server lease find active-address="$leaseActIP"]]; | |
| :if ($leaseBound = 1) do={ | |
| # Emite uma mensagem de log | |
| /log warning message="DHCP LEASE UP MAC=$leaseActMAC IP=$leaseActIP hostname=$custLeaseHost"; | |
| # Cria uma queue para o cliente | |
| /queue simple add comment=$leaseActMAC target=$leaseActIP max-limit=2M/5M; | |
| # Envia uma mensagem para o Telegram | |
| /tool fetch url="https://api.telegram.org/bot{ID_DO_BOT}/sendMessage?chat_id={ID_DO_GRUPO}&text=DHCP LEASE UP \F0\9F\94\B5 MAC=$leaseActMAC IP=$leaseActIP hostname=$custLeaseHost"; | |
| } else={ | |
| /log warning message="DHCP LEASE DOWN MAC=$leaseActMAC IP=$leaseActIP hostname=$custLeaseHost"; | |
| # Remove a queue criada para o cliente | |
| /queue simple remove [find comment=$leaseActMAC]; | |
| /tool fetch url="https://api.telegram.org/bot{ID_DO_BOT}/sendMessage?chat_id={ID_DO_GRUPO}&text=DHCP LEASE DOWN \F0\9F\94\B4 MAC=$leaseActMAC IP=$leaseActIP hostname=$custLeaseHost"; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment