Community discussions

MikroTik App
just joined
Topic Author
Posts: 3
Joined: Fri Feb 05, 2021 11:52 am

ip data type

Fri Feb 05, 2021 11:56 am

Hello! I have an issue with converting str to ip. It returns nil and empty value.
:local content
:local contentLen
:local lineEnd 0
:local line
:local lastEnd 0
:local comma
:local dnsName
:local dnsIp

:set content [/file get [/file find name=flash/test.csv] contents]
:set contentLen [:len $content]

:do {
	:set comma [:find $content "," $lastEnd ]
	:set lineEnd [:find $content "\n" $lastEnd ]
	:set dnsName [:pick $content $lastEnd $comma]
	:set dnsIp [:pick $content ($comma+1) $lineEnd]
	:set lastEnd ($lineEnd+1)
	:if ( [ pick $dnsIp 0 1] !="#" ) do={
		:if ([:len $dnsIp] > 0 && [:len $dnsName] > 0) do={
	:put $dnsIp
                :put [:typeof $dnsIp]
                :set $dnsIp [:toip $dnsIp]
                :put [:typeof $dnsIp]
                :put $dnsIp

		[/ip dns static add address=$dnsIp name=$dnsName]		}	
	} while ($lineEnd < $contentLen)
the output      

invalid value for argument address:
    invalid value for argument ip
    invalid value for argument ipv6
What am I missing?
Thank you!

Who is online

Users browsing this forum: No registered users and 17 guests