Community discussions

MikroTik App
 
mantouboji
newbie
Topic Author
Posts: 40
Joined: Mon Aug 01, 2022 2:21 pm

[7.4] I can‘t know how get IPv6 address in script

Mon Aug 01, 2022 2:36 pm

I tried to get the IPv6 address of bridge1 to update dyndns, use this :

 #:global ipfresh6 [ /ipv6 address get [/ipv6 address find interface="bridge1" ] address ]

but failed with "invalid internal item number"

in fact my addresses are:
[admin@RB4011] /ipv6/address> /ipv6/address/print
Flags: D - DYNAMIC; G, L - LINK-LOCAL
Columns: ADDRESS, FROM-POOL, INTERFACE, ADVERTISE
 #    ADDRESS                       FROM-POOL  INTERFACE   ADVERTISE
 0 DL fe80::d5e2:10a9:173b:11be/64             wg1         no
 1 DL fe80::96ee:554a:5b79:6b2a/64             wg2         no
 2  G fd80:28:602::20/64                       wg1         yes
 3  G fd80:28:602:1::1/64                      wg2         yes
 4  G 240e:xxxx::/64       v6pool     bridge1     yes
 5  G 240e:xxxx::/64       v6pool     vlan1       yes
 6  G 240e:xxxx::/64       v6pool     vlan_iot    yes
 7 DL fe80::855:31ff:feb1:545a/64              bridge1     no
 8 DL fe80::855:31ff:feb1:545a/64              vlan1       no
 9 DL fe80::855:31ff:feb1:545a/64              vlan_iot    no
10 DL fe80::a55:31ff:feb1:544f/64              ether1      no
11 DL fe80::855:31ff:fe38:c292/64              wlan4       no
12 DL fe80::f/64                               pppoe-out1  no
13  G 240e:xxxx::1/64      v6pool     bridge1     yes
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [7.4] I can‘t know how get IPv6 address in script

Mon Aug 01, 2022 2:49 pm

with this:
:local ipv6array [/ipv6 address get [find where interface="bridge1"] address]
you obtain an array of 3 IPv6 addresses because bridge1 have more than one IPv6
240e:xxxx::/64
240e:xxxx::1/64
fe80::855:31ff:feb1:545a/64

and get fail because can retrieve only one IP(v6) at time....


you can omit link-local IPv6, but I do not know why the bridge have two IPv6:
:local ipv6array [/ipv6 address get [find where interface="bridge1" and link-local=no] address]
you obtain an array of 2 IPv6 addresses because bridge1 have more than one IPv6
240e:xxxx::/64
240e:xxxx::1/64

but get still fail because can retrieve only one IP(v6) at time....
 
mantouboji
newbie
Topic Author
Posts: 40
Joined: Mon Aug 01, 2022 2:21 pm

Re: [7.4] I can‘t know how get IPv6 address in script

Mon Aug 01, 2022 3:22 pm

Thanks.

I switch to a new way to resolve this:
:tool fetch url="http://ip6only.me/api/" dst-path="/ip6only"
:delay 1
:local result [/file get "ip6only" contents]

# parse the current IPv6 result
:local resultLen [:len $result]
:local startLoc ( [ :find $result "," 1 ] + 1)
:local endLoc  [ :find $result "," $startLoc ] 
:local ipfresh6 [ :pick $result $startLoc $endLoc ]

:file remove "ip6only"

:put $ipfresh6

 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [7.4] I can‘t know how get IPv6 address in script

Mon Aug 01, 2022 3:38 pm

Do not use NAND or Flash, use https, and remove all the frills:
{
:local test ([/tool fetch url="https://ip6only.me/api/" as-value output=user]->"data")
:set test [:pick $test ([:find $test "IPv6,"] + 5) [:find $test ",v"]]
:put $test
}
Obviously this works until the service is available....
 
mantouboji
newbie
Topic Author
Posts: 40
Joined: Mon Aug 01, 2022 2:21 pm

Re: [7.4] I can‘t know how get IPv6 address in script

Mon Aug 01, 2022 4:27 pm

wonderful!
 
mantouboji
newbie
Topic Author
Posts: 40
Joined: Mon Aug 01, 2022 2:21 pm

Re: [7.4] I can‘t know how get IPv6 address in script

Mon Aug 01, 2022 7:31 pm

Now. this is my lastest script to update both IPv4 and IPv6 address on dyndns.com:

Thank you for your giant help.

:global ddnsuser "USER_NAME"
:global ddnspass "PASSWORD"
:global theinterface "pppoe-out1"
:global ddnshost1 "YOUR_HOST_NAME"

# IPv4, remove /32
:local test   [ /ip address get [/ip address find interface=$theinterface ] address ]
:local ipfresh [ :pick $test 0 [find $test "/"]]

#get from Web
:set   test      ([/tool fetch url="https://ip6only.me/api/" as-value output=user]->"data")
:local ipfresh6  [:pick $test ([:find $test "IPv6,"] + 5) [:find $test ",v" ] ]

:if ([ :typeof $ipfresh ] = nil ) do={
   :log info ("DynDNS: No ip address on $theinterface .")
} else={
   :log info ("DynDNS: IP-Fresh = $ipfresh,$ipfresh6")
   
   #both IPv4 and IPv6 here
   :global str1 "nic/update\?hostname=$ddnshost1&myip=$ipfresh,$ipfresh6&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"

   :set test ([/tool fetch url="https://members.dyndns.org/$str1" user=$ddnsuser password=$ddnspass  as-value output=user]->"data")

   :local logstr  "DynDNS: IP updated to $ipfresh and  $ipfresh6!"
   :log info $logstr
   /tool/e-mail/send to=MY_EMAIL_ADDR  subject=DynDNS body=$logstr
}

Last edited by mantouboji on Mon Aug 01, 2022 7:46 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [7.4] I can‘t know how get IPv6 address in script

Mon Aug 01, 2022 7:35 pm

Thanks,
and thanks for sharing
 
MDAcosta
just joined
Posts: 2
Joined: Wed Mar 22, 2023 5:20 pm

Re: [7.4] I can‘t know how get IPv6 address in script

Thu Mar 23, 2023 9:06 pm

Are you guys getting the complete IPv6 Address or just a portion of it? It doesn't matter how I implement the fetch command, which script I use, or from which service I am looking for the current dynamic IPv6 address, I am always getting a portion of it: 2800:a4:1a48:9a00::
Meanwhile, if I perform a lookup from the server with the curl command, I am getting the whole address at once:
❯ curl http://v6.sync.afraid.org/u/api-key/
Updated domain.com from 2800:a4:1a48:9a00:: to 2800:a4:1a48:9a00:a5a3:3ac6:a0ee:4626

This is an important stuff, since I have to fort forward the required ports in order to accomplish this I require the complete address.
Are you guys experiencing the same or is it just a misconfiguration from my side?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: [7.4] I can‘t know how get IPv6 address in script

Fri Mar 24, 2023 1:43 pm

( the correct syntax is https://v6.sync.afraid.org/u/<API-KEY> )

for me the previous script work as expected with "full" IPv6
and also 2800:a4:1a48:9a00:: still a valid IPv6
 
mikrotip
just joined
Posts: 2
Joined: Sat Sep 10, 2022 3:46 pm

Re: [7.4] I can‘t know how get IPv6 address in script

Tue Apr 18, 2023 10:29 pm

You can try something like this, (e.g. in case you have a dhcp-client over pppoe-client with /64 prefix from ISP) but replace the `bridge-lan` interface name if needed:
:local "ipv6" [/ipv6/address get [:pick [find dynamic global interface=bridge-lan] 0 ] address]
:local "ipv6" [:pick $"ipv6" 0 [:find $"ipv6" "/"]]
In my case it returns exactly one IPv6.

Who is online

Users browsing this forum: No registered users and 12 guests