# We need to use the following globals which must be defined here even :global SYSntpb "1.uk." # Check and set NTP servers - "setntppool" # NTP pools to use (check :global SYSntpa "0.uk." :global SYSsendemail E-mail address to send notifications from # E-mail address to send notifications to # System configuration script - "GlobalVars" The first defines some system variables which are used in other scripts and the second does the grunt work: This script is required as RouterOS does not allow hostnames to be used in the NTP configuration.
This script resolves the hostnames of two NTP servers, compares the result with the current NTP settings and changes the addresses if they're different. :set message message] Īfter new entry is detected, it is saved in "message" variable, which you can use later to parse log message, for example, to get pppoe clients mac address.Īllow use of ntp.org pool service for NTP Now we can write a script to detect if new entry is added. :for i from=( - 1) to=0 do= while ($lineEnd /log print where buffer=pppoeġ3:11:08 pppoe,info PPPoE connection established from 00:0C:42:04:4C:EE This script is useful if you need ip address without netmask (for example to use it in firewall), but " /ip address get address" returns ip address and netmask. :put "ip address $currentIP changed to $newIP" This script will compare if dynamic IP address is changed. :-', '', mac).lower () remove delimiters and convert to lower case mac ''.join (mac.split ()) remove whitespaces assert len (mac) 12 length. import re def formatmac (mac: str) -> str: mac re.sub ('. Sometimes provider gives dynamic IP addresses. This is not the shortest solution, but it accepts all common types of mac formats as inputs. In v3.x it is not possible to create file directly, however there is a workaround Script examples used in this section were tested with the latest 3.x version. This section contains some useful scripts and shows all available scripting features. 2.3 Include custom function in another script.1.14 Other scripts known to work with latest v3.x.Before creating a regular expression pattern we need to first look at the valid IPv4 format. Now, we will input the string to be validated and then create the regex pattern.
In Python, to implement regular expression, firstly we need to import re module.
The main purpose of MAC address is to provide a. It is always unique that means no two devices on a local network could have the same MAC addresses. We know that the MAC address is a hardware address which means it is unique for the network card installed on our PC. I just didn't put enough square brackets. Python Programming Server Side Programming. Jut in case someone come here in the future. I'm on the "reinvent the wheel" side, but it's not my fault :) I see that "use a module" vs "reinvent the wheel" is an ever discussed problem.
#Python mac address string from a simple string code
The class does not work (I don't know probably there isn't a reason to prefer a regex over 'unpack' or the use of a module, in this case, since this regex is not really more readable than other methods.Īnyway I'm more familiar with regexes than with unpack or the Net::MAC module, so there is a chanche that I will recognize and understand that sooner when looking again at my code in the future.Īs for modules, I often avoid (or completely overlook) them, because I usually have little or no control on the systems I work onto (so installing a module can be a tricky or impossible task).