Page 1 of 1
[7.4] I can‘t know how get IPv6 address in script
Posted: Mon Aug 01, 2022 2:36 pm
by mantouboji
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
Re: [7.4] I can‘t know how get IPv6 address in script
Posted: Mon Aug 01, 2022 2:49 pm
by rextended
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:](//cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/31ff.svg)
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....
Re: [7.4] I can‘t know how get IPv6 address in script
Posted: Mon Aug 01, 2022 3:22 pm
by mantouboji
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
Re: [7.4] I can‘t know how get IPv6 address in script
Posted: Mon Aug 01, 2022 3:38 pm
by rextended
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....
Re: [7.4] I can‘t know how get IPv6 address in script
Posted: Mon Aug 01, 2022 4:27 pm
by mantouboji
wonderful!
Re: [7.4] I can‘t know how get IPv6 address in script
Posted: Mon Aug 01, 2022 7:31 pm
by mantouboji
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
}
Re: [7.4] I can‘t know how get IPv6 address in script
Posted: Mon Aug 01, 2022 7:35 pm
by rextended
Thanks,
and thanks for sharing
Re: [7.4] I can‘t know how get IPv6 address in script
Posted: Thu Mar 23, 2023 9:06 pm
by MDAcosta
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:](//cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1a48.svg)
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:](//cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1a48.svg)
9a00:: to 2800:a4
![:1a48:](//cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/1a48.svg)
9a00:a5a3
![:3ac6:](//cdn.jsdelivr.net/gh/twitter/twemoji@latest/assets/svg/3ac6.svg)
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?
Re: [7.4] I can‘t know how get IPv6 address in script
Posted: Fri Mar 24, 2023 1:43 pm
by rextended
( 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
Re: [7.4] I can‘t know how get IPv6 address in script
Posted: Tue Apr 18, 2023 10:29 pm
by mikrotip
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.