NO WAY?! AI writes Mikrotik-Scripts...

Thats new to me… I said:

wirte a fancy mikrotik-script, so i can impress the guys in the mikrtoik-forum!

AI said:

Sure, here’s a fancy script that demonstrates some advanced features of MikroTik RouterOS scripting:

It came up with this stuff :laughing: :laughing: :laughing: :laughing: (dont know if it works)


# This script sets up a simple hotspot with user authentication
# and bandwidth limiting, and sends a welcome message to the user
# upon successful login.

# First, define some variables for the hotspot and user settings
:local hotspotName "My Fancy Hotspot"
:local hotspotAddress "192.168.88.1"
:local hotspotDns "8.8.8.8"
:local hotspotNetmask "255.255.255.0"
:local hotspotLeaseTime "1d"
:local hotspotUamSecret "mysecret"
:local hotspotUamServer "http://$hotspotAddress/hotspot"
:local hotspotMaxUsers "20"
:local userRateLimit "512k/512k"

# Next, create the hotspot interface and set the required settings
/interface wireless
set [ find default-name=wlan1 ] ssid=$hotspotName
set [ find default-name=wlan1 ] mode=ap-hotspot

/ip pool
add name=hotspot-pool ranges=$hotspotAddress/$hotspotNetmask

/ip hotspot profile
set [ find default=yes ] address-pool=hotspot-pool
set [ find default=yes ] dns-server=$hotspotDns
set [ find default=yes ] lease-time=$hotspotLeaseTime
set [ find default=yes ] login-by=http-chap
set [ find default=yes ] hotspot-address=$hotspotAddress
set [ find default=yes ] hotspot-service=http
set [ find default=yes ] hotspot-service=https
set [ find default=yes ] hotspot-service=ssh
set [ find default=yes ] hotspot-service=ftp
set [ find default=yes ] hotspot-service=dns
set [ find default=yes ] hotspot-service=smtp
set [ find default=yes ] hotspot-service=pop3
set [ find default=yes ] hotspot-service=imap
set [ find default=yes ] hotspot-service=radius
set [ find default=yes ] hotspot-service=winbox
set [ find default=yes ] hotspot-service=www
set [ find default=yes ] hotspot-service=api

/ip hotspot user profile
set [ find default=yes ] rate-limit=$userRateLimit

/ip hotspot
add address=$hotspotAddress name=$hotspotName profile=default

# Now, define the login and logout scripts that will be executed
# when a user authenticates to the hotspot.

# The login script sends a welcome message to the user and adds a
# bandwidth limit to their connection.
:local loginScript ""
:local logoutScript ""

:set loginScript [ /file get hotspot-login.rsc contents ]
:set logoutScript [ /file get hotspot-logout.rsc contents ]

/ip hotspot user profile
set [ find default=yes ] on-login=$loginScript
set [ find default=yes ] on-logout=$logoutScript

# Finally, set the hotspot to start automatically on boot and
# enable the hotspot service
/system script
add name=hotspot-start policy=ftp,reboot,



And a short AI-Mikrotik poem:

Mikrotik, oh Mikrotik,
A router that’s truly quick,
Connecting all our devices,
With lightning-fast speeds.

Through rain or wind or snow,
You keep our connections flowing,
Your magic touch never fades,
In so many different ways.

Mikrotik, oh Mikrotik,
A hero of the internet,
We thank you for your service,
Our gratitude won’t be inert.

AI?

Say: “write a mikrotik-script to convert IPv4 address to binary value”…

Say: “write a standard POSIX RegEx for identify IPv6”…


Who is that idiot who fed bad data or badly programmed the AI?
Just for example:
/interface wireless
set [ find default-name=wlan1 ] mode=ap-hotspot

I think you have “extended” someones lifespan, and the cat remains with 9 lives. May AI leave us alone a bit longer.



# Set the IPv4 address to be converted
:local ipv4Address "192.168.0.1"

# Split the IPv4 address into its octets
:local octets [:toarray $ipv4Address]

# Initialize the binary string
:local binaryString ""

# Iterate through each octet and convert it to binary
:foreach octet in $octets do={
  # Convert the octet to binary
  :local binaryOctet [:tobinary $octet]

  # Pad the binary octet with leading zeros until it has 8 digits
  :while ([:len $binaryOctet] < 8) do={
    :set binaryOctet "0$binaryOctet"
  }

  # Append the binary octet to the binary string
  :set binaryString "$binaryString$binaryOctet"
}

# Print the binary string
:put $binaryString



This script first sets the IPv4 address to be converted in the ipv4Address variable. It then splits the address into its octets using the :toarray function and stores them in the octets variable.

Next, the script initializes the binaryString variable as an empty string. It then iterates through each octet in the octets array and converts it to a binary value using the :tobinary function.

The binary value is then padded with leading zeros until it has 8 digits using a while loop and the :len function. Finally, the binary octet is appended to the binaryString variable.

After the loop completes, the script prints the final binary string using the :put command.

I hope this helps! Let me know if you have any questions.




^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$



This regular expression will match any valid IPv6 address, including addresses with an embedded IPv4 address, and addresses with a link-local scope identifier.

Note that this regular expression may not work with all regex implementations, as it is written in POSIX extended regular expression syntax. Some implementations may require modification to support this syntax.

For you, what the AI says:



To our dear anav,

We are pleased to present you with this MTUNA certificate in recognition of your dedication and contributions to the Mikrotik-Forum community.

MTUNA stands for Mikrotik Training and User Networking Association. It is a community of like-minded individuals who are passionate about learning and sharing knowledge about Mikrotik networking technology.

Through your participation and contributions in the forum, you have demonstrated a strong commitment to helping others and advancing the field of networking. You are a valuable member of the MTUNA community and we are grateful for all that you do.

Congratulations on receiving this MTUNA certificate and thank you for being an invaluable member of our community.

Sincerely,
The MTUNA Team

I scolded AI:


It looks like the issue you are experiencing is that the "mode" property of the wireless interface is set to "ap-hotspot", but this value is not recognized by the router.

In Mikrotik routers, the mode of a wireless interface can be set to either "ap" (access point) or "station" (client). It appears that "ap-hotspot" is not a valid value for the mode property.

To set up a hotspot using this script, you will need to change the value of the "mode" property to "ap". For example:

/interface wireless
set [ find default-name=wlan1 ] ssid=$hotspotName
set [ find default-name=wlan1 ] mode=ap

This will set the wireless interface to operate as an access point, and will allow you to use the rest of the script to configure the hotspot.

I hope this helps! If you have any further questions or issues, don't hesitate to ask.

Again AI / AI programmers errors, “ap” mode do not exist(*)…

(*) I do not have wifiwave2 devices for test, but is “ap-bridge” the right value

The AI has “MTUNA”, but is still unable to set the wireless mode correctly?

really things shot there at random …
(it would be nice if toarray actually directly converts an IP to bytes… but that’s another story)
{
:local ipv4Address “192.168.0.1”
:local octets [:toarray $ipv4Address]

:put [:typeof $octets]
:put “items on array $[:len $octets]”
:put “octets is >$octets<”
:put “$($octets->0) $[:typeof ($octets->0)]”
:put “$($octets->1)”
}
“octets” variable is the conversion of a string (ipv4Address) to one array, with one string inside…


this do not work also if ipv4Address is CORRECTLY set as IP instead of string…
{
:local ipv4Address [:toip 192.168.0.1]
:local octets [:toarray $ipv4Address]

:put [:typeof $ipv4Address]
:put [:typeof $octets]
:put “items on array $[:len $octets]”
:put “octets is >$octets<”
:put “$($octets->0) $[:typeof ($octets->0)]”
:put “$($octets->1)”
}

But… Does the AI have early access to OpenROS® 12.25?
:laughing:
If AI invents anything, it should first of all do as people who really have intelligence do…
Check first il those instructions exist...


About previous post, give this link to the AI:

Probably can learn something....
:global ip2array do={
:local ip [:toip $1]
:local array [:toarray ""]
:if ([:typeof $ip] != "ip") do={:return $array}
:set ($array->0) $ip
:set ($array->1) [:tonum (($ip >> 24) & 0.0.0.255)]
:set ($array->2) [:tonum (($ip >> 16) & 0.0.0.255)]
:set ($array->3) [:tonum (($ip >> 8 ) & 0.0.0.255)]
:set ($array->4) [:tonum (($ip >> 0) & 0.0.0.255)]
:return $array
}

space on forum between 8 and ) because if not present, is translated to the emoticon :sunglasses: ...

I'm not saying it's the best possible script, but it's close to it, and above all... it works...

I really hope it works, I’ve always been too lazy to study one actually working, given the complexity of the thing …

But the RegEx fail (MikroTik or not)
For example, this valid IPv6 is not recognized…
::4321:5678:91.123.4.56

It might be better not to take this so seriously :laughing:

P.S.:
I'm too lazy for IPv6 RegEx, but not for this: "write a mikrotik-script to convert IPv4 address to binary value"

Convert IPv4 to binary data:
:global ip2bin do={
:local number [:tonum [:toip $1]]
:local ret ""
:for i from=0 to=31 step=1 do={
:set ret "$(($number >> $i) & 1)$ret"
:if ([:tostr $i]~"^(7|15|23)$") do={:set ret "$2$ret"}
}
:return $ret
}

no separator

:put [$ip2bin 192.168.0.1]

with separator for each 8 bit (can specified any, also "\r\n")

:put [$ip2bin 192.168.0.1 "."]
:put [$ip2bin 192.168.0.1] = 11000000101010000000000000000001

:put [$ip2bin 192.168.0.1 "."] = 11000000.10101000.00000000.00000001

:put [$ip2bin 192.168.0.1 "\r\n"] =
11000000
10101000
00000000
00000001

:+1::+1::+1:
however it programs better than many other improvised programmers here on the forum and on youtube & co. …
:laughing: :laughing: :laughing: :laughing:

Gosh, the self-proclaimed MTUNA team AI “thing” even got meaning of MTUNA wrong. As the founder of MTUNA certification programme, our beloved @anav could tell us that MTUNA stands for “MikroTik Uncertified Network Amateur” … has nothing much to do with what AI insinuates.

It shows how low are AI’s skills of detecting sarcasm … the fact that @anav is on the extreme side doesn’t excuse AI a bit.

Actually… http://forum.mikrotik.com/t/mikrotik-mtcna-home-learning/137726/6 :smiley:

You should correct it and tell ChatGPT what is right. It is capable of some learning :slight_smile:

Hi @normis,
any plans to release OpenROS® 12.25 to the public?
(please be nice with the answer, Christmas is just around the corner) :laughing:

... and ... AI is listening and learning :laughing:

Uh, sorry … I stand corrected … the founder of MTUNA certificate programme, our beloved @Sob :smiley:

AI, did you get this?