Community discussions

MikroTik App
 
CenturyG
just joined
Topic Author
Posts: 12
Joined: Tue Nov 29, 2022 4:43 pm

Scripting to calculate time to disable ports

Thu Dec 01, 2022 7:37 pm

Looking for a script that would calculate up time/down time from the last time it was up and if it's been 48hrs past the current date time to disable ports.

Also, how to determine current time to last link time up/down to convert then compare to which one is greater.

Not a programmer here just a network admin that's trying to learn.

Scenario: Router goes out gets plugged into network, script fires off to open vpn tunnel to router and ports are disabled, tech calls network admin to looking to open those disabled ports then have a script that will run every 10 minutes comparing link up-time and down time to determine if it's been past 48hrs to disable the ports. Trying to eliminate lost or stolen, misplaced routers that are out in the field that could be a security risk.
 
CenturyG
just joined
Topic Author
Posts: 12
Joined: Tue Nov 29, 2022 4:43 pm

Re: Scripting to calculate time to disable ports

Tue Dec 06, 2022 8:15 pm

Really needing a script for 6.48.6 "Looking for a script that would calculate up time/down time from the last time it was up and if it's been 48hrs past the current date time to disable ports."

I guess it would need to be converted for date and time to numbers and then if date/time of last link is either greater than or less that down time within a 48hr timespan then the ports would need to be disabled(2-10).

I'm not a programmer so any assistance would be great.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Scripting to calculate time to disable ports

Tue Dec 06, 2022 9:38 pm

Wouldn't using "the dude" be easier than writing a script? it already has alert and monitors, which you can configure to do something after X hours of outage. Likely much more than you could ever script.

Writing a script might not be so easy to solve your problem. See Mikrotik doesn't know much about "dates". So the data you need in the /interface for "last-link-up-time" and "last-link-down-time" BUT there strings you'd have to parse in a script. Or you could use "netwatch" and script there to set some variable instead with the value from :timestamp stored, but then variable don't by default survive a reboot. Again solvable... But all the things start adding up, for what sounds like a network monitor tool (and Mikrotik's is free). The dude has it's own, more "Excel like" functions/code to do more advanced things, but your needs would see to meet with a "probe" and perhaps a "notification" tied to the probe.
 
CenturyG
just joined
Topic Author
Posts: 12
Joined: Tue Nov 29, 2022 4:43 pm

Re: Scripting to calculate time to disable ports

Tue Dec 06, 2022 9:51 pm

Wouldn't using "the dude" be easier than writing a script? it already has alert and monitors, which you can configure to do something after X hours of outage. Likely much more than you could ever script.

Writing a script might not be so easy to solve your problem. See Mikrotik doesn't know much about "dates". So the data you need in the /interface for "last-link-up-time" and "last-link-down-time" BUT there strings you'd have to parse in a script. Or you could use "netwatch" and script there to set some variable instead with the value from :timestamp stored, but then variable don't by default survive a reboot. Again solvable... But all the things start adding up, for what sounds like a network monitor tool (and Mikrotik's is free). The dude has it's own, more "Excel like" functions/code to do more advanced things, but your needs would see to meet with a "probe" and perhaps a "notification" tied to the probe.
How would you do that in Netwatch, never used it and not familiar with it? My boss really wants a script and I'm not sure how to break it down to him.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Scripting to calculate time to disable ports

Tue Dec 06, 2022 10:01 pm

As noted, a script isn't that easy here. It take some homework to that, thus my point.

As stated, your problems seem more like networking monitoring (e.g. Dude). Or using something like User Manager / RADIUS if the "de-auth" part is the most important. If have a lot or these things are so critical, do you want a [potentially] flimsy script to monitoring them?

Good luck.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scripting to calculate time to disable ports

Tue Dec 06, 2022 11:30 pm

before continuing, remember that the router does not have an internal battery, it does not keep accurate time,
so if the router is powered off and on again (not simply rebooted and ignoring more detailed details) it does not have the correct time,
and the uptime and downtime reported by the interfaces is NOT updated when the router manages to synchronize the time on the internet.
Maybe you find yourself with the last up on December 6th and the last down on December 1st...
how do you understand if one of the two dates is "random" because the clock has been synchronized recently?

A script that would tell the truth about it would be extremely complex...
 
CenturyG
just joined
Topic Author
Posts: 12
Joined: Tue Nov 29, 2022 4:43 pm

Re: Scripting to calculate time to disable ports

Wed Dec 07, 2022 5:26 pm

Thanks guys for your impecable insight to this, My boss is going to take it on with coming up with a script, guess will see what he comes up with.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11982
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Scripting to calculate time to disable ports

Fri Dec 09, 2022 1:00 pm

Thanks guys for your impecable insight to this, My boss is going to take it on with coming up with a script, guess will see what he comes up with.
Read here:
viewtopic.php?p=971181#p971181

Who is online

Users browsing this forum: Bing [Bot] and 14 guests