Mikrotik Scripting Question - How to add ip's and mac addresses from ARP list to dhcp - server / leases??? (Please Help) - scripting

I was wondering if you can help me with the following:
I am using Mikrotik scripting on Winbox64, and I want to basically add all the ip's and their mac addresses to dhcp-server leases from the ARP list
I am using currently a command on Winbox64 Mikrotik terminal: ip dhcp-server lease > add address=xxx.xx.xx.xx mac-address=xx:xx:xx:xx:xx:xx,
so it adds manually each address individually,
but I want to move all of them automatically, with perhaps a code loop.
Would it be possible ? and if so, how would the code be constructed ?
I was thinking foreach loop, but still not sure...
Forgive me if it's too obvious I am only a beginner on this, and I spent some time figuring it out
Thank you in advance!

This should be the start of something. Loop throught the arp. if the mac doesn't exist in leases add the lease.
:local leaseexists
:foreach ARPID in=[/ip arp find] do={
:local ipaddr [/ip arp get $ARPID address]
:local macaddr [/ip arp get $ARPID mac-address]
:local iface [/ip arp get $ARPID interface]
:if ( $macaddr~":" ) do={
:local leaseexists 0;
:foreach LEASEID in=[/ip dhcp-server lease find where mac-address="$macaddr"] do={
:set leaseexists 1
}
:if ( $leaseexists = 0 && $iface = "INSIDE") do={
:local date [/system clock get date];
:local time [/system clock get time];
/ip dhcp-server lease add address=$ipaddr mac-address=$macaddr server=all comment="arp-to-lease {*date:$date*} {*time:$time*}"
:foreach LEASEID in=[/ip dhcp-server lease find where mac-address="$macaddr"] do={
/tool fetch url="http://notify.updateserver.net/notify/lease/$LEASEID" keep-result=no
}
}
}
}

Related

What does RHPort mean in tinyusb?

Looking through tinyusb, am a bit confused on the meaning of RHPort - cannot find much on Internet, grepping through source gives me results like:
tinyusb/docs/info/changelog.rst:- Add rhport to hcd_init()
tinyusb/docs/info/changelog.rst: - Support multiple usb ports with rhport=1 is high
...
tinyusb/examples/device/cdc_dual_ports/src/tusb_config.h:// RHPort max operational speed can defined by board.mk
...
tinyusb/examples/device/cdc_dual_ports/src/tusb_config.h:// Device mode with rhport and speed defined by board.mk
...
tinyusb/examples/device/cdc_msc/src/tusb_config.h:// RHPort number used for device can be defined by board.mk, default to port 0
...
... and trying to think of what could "RH" possibly stand for as an acronym, the only thing that pops in my head is "Right Honourable" :)
So, what is the meaning of RHPort in (tiny)USB?
Ok, I think I found at least some sort of an explanation ...
Anyways, https://docs.tinyusb.org/en/latest/reference/getting_started.html says:
Port Selection
If a board has several ports, one port is chosen by default in the
individual board.mk file. Use option PORT=x To choose another port.
For example to select the HS port of a STM32F746Disco board, use:
$ make BOARD=stm32f746disco PORT=1 all
A bit tricky to find where that PORT is used, then - but for the above example, it is most likely in https://github.com/hathach/tinyusb/blob/master/hw/bsp/stm32f7/family.mk :
...
CFLAGS += \
...
-DBOARD_TUD_RHPORT=$(PORT)
...
... which then gets used in e.g. https://github.com/hathach/tinyusb/blob/master/examples/device/dfu_runtime/src/main.c :
...
// init device stack on configured roothub port
tud_init(BOARD_TUD_RHPORT);
...
... which reveals, that "RH" in "RHPort" most likely stands for "Root Hub".
So, my guess is, that for boards that have multiple physical USB port connectors, the RHPort determines which of those ports is tinyusb targeting?

TinkerBoard 2s Serial Connection UART0

i am trying to connect my PC and my TinkerBoard 2s via UART0.
I found this forum post:
https://forums.debian.net/viewtopic.php?t=149981
which relates to this on page 11:
https://tinker-board.asus.com/images/doc/download/Tinker_Edge_R_Getting_Started.pdf
So what i already did is:
in /dev/config.txt
"intf:fiq_debugger=on" → "intf:fiq_debugger=off"
"#intf:uart0=off" → "intf:uart0=on"
"overlay=" → "overlay=console-uart0-overlay"
My Question now:
where do i have to put
uart1 = Serial("/dev/ttyS0=",115200)
uart3 = Serial("/dev/ttyS4=",9600)
I put it at the end of config.txt, but when i "cat /dev/ttyS0" on TinkerBoard and connect via PUTTY on COM3 and 115200, nothing happens...
Do i have to put it in the same file (config.txt)? or into the cmdline.txt?
Did i forgot something? Do I have to change "overlay=" -> "overlay=console-uart0-overlay"?
(I dont care if i will get to console or sending chars for now)
thank you

upstart script to start a task after hardware clock has been started

I have a process that tries to make an SSL connection after start up, but that fails if the clock has not yet been set (the dates don't match the effective dates on the certificates). Is it possible to configure upstart to only start the process after the internal clock is set?
The default setting for the clock is 2010-01-01, so perhaps something like date >= 2014 is sufficient (obviously not legit upstart syntax, but the concept holds).
The best I could figure out was to start up after NTP has started, but that doesn't necessarily mean the clock has been set as the network connection establishment may be delayed or not available for a while.
The simple solution is probably to just poll the date and wait 500ms or whatever before trying again if the date isn't sane yet.
Here's what I ended up doing:
start on started connman
stop on runlevel [016]
script
YEAR=$(date +'%Y')
until [ $YEAR -ge "2014" ]; do
sleep 5
YEAR=$(date +'%Y')
done
python access_point.py
end script
I wait until the connection manager is running and then I check the year every 5 seconds until the year is 2014 or greater.

Sending Mail in seaside+Gemstone " a Message: NotUnderstood occurred (error 2010), a UndefinedObject does not understand #'isEmpty' "

Tried with a similar question earlier, but could not I make headway. So I did new tests and here is the new question:
I did a brand new installation of PHARO 1.4 and GEMSTONE 3.0.1.2 on the same machine. (Linux CENTOS). Loaded seaside 3.0 in Pharo and version 3.0.7.1 in Gemstone using the latest version of Gemtools (1.0 beta 87) with the latest version of glass workspace (1.0 beta 8.7.4).
I opened the workspace and evaluated:
(WAEmailMessage
from: (WAEmailAddress address: 'xx#aa.com' username: 'fromMe')
to: (WAEmailAddress address: 'shyam#localhost' username: 'shyam')
subject: 'Email Test')
body: 'This is a Test Email sent';
send.
(BTW, As the default mail host in Gemstone is "mailhost", I added the following line to the /etc/hosts file127.0.0.1 localhost mailhost ).
On Pharo the message is sent and received correctly, while in Gemstone I get
a MessageNotUnderstood occurred (error 2010), a UndefinedObject does not understand #'isEmpty', in the method
readSmtpResult
| result firstChar |
[self readWillNotBlockWithin: 5000]
whileFalse: [GsFile stderr log: 'Waiting for server to write...'].
result := self readString: 500.
result isEmpty =========================> HERE result is "nil".
ifTrue:
[self log: 'Empty result'.
^false].
The reason being that result returns a nil.
I tried with similar results also on MAC OS X which instead went into a loop in the lines above.
Using tcpdump -X -i lo tcp port 25 and WireShark, I noticed that for GEMSTONE, I saw NO activity while the packets were correctly exchanged for PHARO.
Evidently, I am doing something terribly wrong to get it wrong on two different systems.
Any idea ?
Thanks
Shyam.
result is nil because #readString: returned nil.
It seems that the peer does not send any data. As you already traced that there is no activity on port 25 going on, are you sure that the SMTP parameters are correct?
Seaside-Email contains code that you can use to configure your SMTP-Server.
Given you have your Seaside application seasideApp, you can do the following:
seasideApp configuration
addParent: WAEmailConfiguration instance.
seasideApp
preferenceAt: #smtpServer put: 'your.smtp.host';
preferenceAt: #smtpPort put: 25;
preferenceAt: #smtpUsername put: 'your.smtp.username.or.nil.if.unecessary';
preferenceAt: #smtpUsername put: 'your.smtp.password.or.nil.if.unecessary';
yourself.
Note that #smtpServer and smtpPort must be configured the way described, as they are used in the GemStone version of GRPlatform>>#seasideDeliverEmailMessage:. I opted to deliberately not use the GemStone defaults.
Also, setting the SMTP parameters this way is ment to work cross-platform; if it does not, please contact me directly.

Fast Way to reserve Ports in VB.NET

I have a need for my application to reserve certain port numbers. All I need to do is reserve them. I don't have to receive messages or anything. What is the fastest and easiest way to do this. I've tried the following:
ClientNetwork.hack_port_reserver1 = New UdpClient("localhost", 2020)
ClientNetwork.hack_port_reserver2 = New UdpClient("localhost", 2220)
ClientNetwork.hack_port_reserver3 = New UdpClient("localhost", 2021)
ClientNetwork.hack_port_reserver4 = New UdpClient("localhost", 2221)
But I think this reserves a random port to listen for messages coming from the port #'s I specified, because when I look at my ports I see that my application has reserved ports 4702 - 4705, when I wanted it to reserve the ports listed above.
I know that my application should not have to do this, but I don't work in fluffy coder candy land where everything is designed properly.
Thanks
Well I was closer to my answer than I thought. The following works:
ClientNetwork.hack_port_reserver1 = New UdpClient(New Net.IPEndPoint(address, 2020))
ClientNetwork.hack_port_reserver2 = New UdpClient(New Net.IPEndPoint(address, 2220))
ClientNetwork.hack_port_reserver3 = New UdpClient(New Net.IPEndPoint(address, 2021))
ClientNetwork.hack_port_reserver4 = New UdpClient(New Net.IPEndPoint(address, 2221))