Archive for the ‘Scripting’ Category
Posted by jpluimers on 2017/07/25
I’ve been using cURL but always had a feeling not to its potential basically because the cURL man page [WayBack] is both massive and lacks concrete useful practical examples.
For instance, I knew about the --header and --verbose options (I always use verbose names even though shorter -H and -v exist) to pass a specific header and get verbose output, but the man page basic examples like this by Tader:
curl --header --verbose "X-MyHeader: 123" www.google.com
source: How to send a header using a HTTP request through a curl call? – Stack Overflow [WayBack]
There are some more examples at bropages.org/curl but they’re hardly organised or documented.
So I was really glad I found the below answer [WayBack] by Amith Koujalgi to web services – HTTP POST and GET using cURL in Linux – Stack Overflow.
But first note that recent versions (around 7.22 or higher) of cURL now need to combine the --silent and --show-error (or in short -sS) parameters to suppress progress but show errors: linux – How do I get cURL to not show the progress bar? – Stack Overflow [WayBack]
Back to the examples
Read the rest of this entry »
Posted in *nix, Communications Development, cURL, Delphi, Development, HTTP, https, Internet protocol suite, JavaScript/ECMAScript, JSON, Power User, REST, Scripting, Security, Software Development, TCP, TLS, XML, XML/XSD | 1 Comment »
Posted by jpluimers on 2017/07/25
For my own reference:
–jeroen
Posted in Development, RouterOS, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2017/07/18
Earlier, I wrote “:for loops are a strange beast so I will elaborate on those in a separate post.” so now is the time to do that.
The :for loop documentation is very dense:
| Command |
Syntax |
Description |
| for |
:for <var> from=<int> to=<int> step=<int> do={ <commands> } |
execute commands over a given number of iterations |
So a for loop has these elements:
Luckily, the old RouterOS 2.7 documentation on loops (which they’ve revamped after Router OS 2.7 removing many useful examples) has this:
:for – It has one unnamed argument, the name of the loop variable. from argument is the starting value for the loop counter, tovalue is the final value. This command counts loop variable up or down starting at from and ending with to, inclusive, and for each value it executes the do statement. It is possible to change the increment from the default 1 (or -1), by specifying the stepargument.
[admin@MikroTik] > :for i from=1 to=100 step=37 do={:put ($i . " - " . 1000/$i)}
1 - 1000
38 - 26
75 - 13
[admin@MikroTik] >
You might think that from= the start value, to= the finish value and the loop won’t execute when step= a positive value and from= larger than to=. Or that without a step= the loop will always iterate in ascending order.
Wrong! And wrong!
So it’s time for some…
:for loop examples
Read the rest of this entry »
Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2017/07/05
Thanks to ZeroByte answering at [Answered] Where are ip firewall address-list timeout values documented – MikroTik RouterOS [WayBack] which I edited a bit here:
I haven’t seen anything specific to the format of these time tokens, but the firewall add-to-address-list timeout is documented here:
http://wiki.mikrotik.com/wiki/Manual:IP … Properties…It seems to take the same format as any other similar duration-related input I’ve encountered:
- a raw number is interpreted as seconds
You can specify a number as another duration with tokens:
- s = seconds (default)
- m = minutes
- h = hours
- d = days
- w = weeks
A few aspects:
- Tokens can combine be in any order
- Whitespace is ignored
So these are all valid:
2s 2h 2w
1w2d3h4m5s
5s4m3h2d1w
- Days and weeks just get added together. If you specify 1w8d, this is the same as 2w1d
- The last value specified may be in h:m:s format or in h:m (omit seconds)
- Interestingly, if you mix and match, they just get added:
- “1d 2h 12:30” -> “1d 14:30:00”
- Values larger than 536870911 seconds are stored and tracked but when displayed show as 0sec.
(248 days, 13:13:55)
- The maximum value is 4294967295 seconds (which is the maximum 32-bit value)
This decodes to: 7101w3d6h28m15s as the largest value….
(7101 weeks is ~136 years counting for leap years, by the way)
–jeroen
Posted in Development, Internet, MikroTik, Power User, RouterOS, routers, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2017/06/28
Gosh, bash can be a pain. So here are some more links that proved to be useful in the past:
–jeroen
Posted in bash, Development, Scripting, Software Development | Leave a Comment »
Posted by jpluimers on 2017/06/27
Since I always forget:
for /l %1 in (1,2,200) do echo %1 >> text-%1.txt
This creates files with incremental filenames like this:
text-1.txt
text-3.txt
...
text-199.txt
–jeroen
via: For – Loop through a range of numbers | Windows CMD | SS64.com [WayBack]
Posted in Batch-Files, Development, Scripting, Software Development | 4 Comments »
Posted by jpluimers on 2017/06/26
Edit 20260501: be careful, as this damaged the NAND memory of my router because of too many write cycles. Root cause: too high update frequency.
Interesting: middelink/mikrotik-fwban: Use your Mikrotik firewall to do fail2ban like blocking of unwanted IPs. Written in Go.
It might beat these (that just count SSH connections, not failed connection attempts)
Read the rest of this entry »
Posted in Development, Hardware, Internet, MikroTik, Network-and-equipment, Power User, RouterOS, routers, Scripting, Software Development, WinBox | Leave a Comment »
Posted by jpluimers on 2017/06/21
For one of my VMs I forgot to note which of the initial password I had changed, so I wanted to check them.
Since I didn’t have a keyboard attached to the console and ssh wasn’t allowing root, I needed an alternative than actual login to test the passwords.
Luckily /etc/shadow, with getent and openssl came to the rescue.
Since getent varies per distribution, here is how it works on OpenSuSE:
Read the rest of this entry »
Posted in *nix, *nix-tools, ash/dash, bash, bash, Development, Encoding, Hashing, Linux, md5, openSuSE, Power User, Scripting, Security, SHA, SHA-256, SHA-512, Software Development, SuSE Linux | Leave a Comment »
Posted by jpluimers on 2017/06/20
One day I need to research how to get the conversions right for this: How do I Check DHCP Lease info in terminal – Ars Technica OpenForum as I think that ipconfig getoption en0 lease_time gives me the value in a different format than date -r expects.
Also:
At T1 seconds (typically set to 0.5*lease_time) after the last successful renewal, the DHCP client attempts to renew it’s lease with the DHCP server that granted it’s current address via unicast. If unsuccessful, at T2 seconds (typically set to 0.875*lease_time) after the last renewal, the DHCP client attempts to rebind with any DHCP server via multicast.
–jeroen
Posted in Apple, bash, Development, Mac, Mac OS X / OS X / MacOS, OS X 10.10 Yosemite, OS X 10.11 El Capitan, OS X 10.9 Mavericks, Power User, Scripting, Software Development | Leave a Comment »