Query IP address from url

Hi, is it possible to query the (my) IPv6 adress from my dynv6 domain?

I would like to compare my IPv6 with the stored address in dynv6.

If they are not equal, I would like to update.

the script Update script for dynv6.com to set your IPv4 address and IPv6 prefix · GitHub looks only to the internal stored IP, it don´t query the stored IPv6 in dynv6.

with exec nslookup I got a payload like this:
Server: 127.0.0.1
Address: 127.0.0.1#53

Non-authoritative answer:
Name: ****.dynv6.net
Address: 2a01:6030:c01d:4a01:22:24ff:fe20:ca68

how can I get only the IPv6 from payload?

Feed it into a debug node please and show us what is there.

it is the payload from debug

1

Server:		127.0.0.1
Address:	127.0.0.1#53

Non-authoritative answer:
Name:	mydomain.dynv6.net
Address: 2a00:6020:b02d:1a04:11:32ff:fd48:eb43


I found " node-red-contrib-string " - maybe with this node I could fetch the IPv6 from string ?

I would start by sending it through a Split node. The default behaviour should be to split on new line, so that should give you a sequence of messages, one for each line. Connect a debug node to the output of the Split node and make sure that is what you get. Then feed it into a Switch node configured to send messages where msg.payload Contains the string Address to output 1. Other messages will be discarded. Again use a debug node to check you now just have the two Address messages. Then feed through another Switch node to send messages that contain a dot character to output 1 and Otherwise to output 2. Then on output 2 you should just get the line you want. Now feed through another Split node, configured to split on space and you should get two messages, one with Address and one with the ip address. Finally use another Switch node to send messages containing Address to output 1 and Otherwise to output 2 and you should get the answer you want on output 2.

Alternatively you could write some javascript in a function node that does effectively the same thing. If you are competent with javascript then do that, otherwise do it as above.
Probably it could also be done with a clever regular expression.

1 Like

I got it:

:nerd_face: :+1:

this compares the IPv6 with the IPv6 from dynv6.
If it´s not equal, it will update Prefix & Record from dynv6.

Or with a simple jsonata expression in change node:

/* only outputs the address if "Address:" is appearing twice in the text. */
(payload~>$split(/Address:/))[2]~>$trim()
1 Like

thank you.

Do you know an expression where I can cut the prefix from hostname?
Input: 2001:0db8:85a3:08d3:1319:8a2e:0370:7344
Output1: 2001:0db8:85a3:08d3
Output2: 2001:0db8:85a3:08d3:aaaa:bbbb:cccc:dddd (static)

I would like also to join the (new) prefix with an other (static) interface identifier for an other dynv6 domain.

See:

So it is a combination of the following 2 jsonata expressions:

payload~>$substring(0,19)
(payload~>$substring(0,19)) & ":aaaa:bbbb:cccc:dddd"
1 Like

nice, but sometimes the prefix is different, for example:
2001:0db8:85a3:08d3
2001:b8:85a3:d3

is it possible to split after the 4th ":" ?

You can split the whole string then slice the array and rejoin.

$trim(
    $join(
        $split($$.payload, ":")[[-8..-5]]
        , ":"
    )
) & ":aaaa:bbbb:cccc:dddd"

output

2a00:6020:b02d:1a04:aaaa:bbbb:cccc:dddd
1 Like

but where can I paste this jasonata ? :thinking:

In a change node as you have been doing, feed the jsonata the output of the exec nslookup.

[{"id":"80f3a3ecc746e5e6","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Server:\t\t127.0.0.1 Address:\t127.0.0.1#53  Non-authoritative answer: Name:\tmydomain.dynv6.net Address: 2a00:6020:b02d:1a04:11:32ff:fd48:eb43","payloadType":"str","x":250,"y":100,"wires":[["80898fe14df9b252"]]},{"id":"80898fe14df9b252","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$trim(\t    $join(\t        $split($$.payload, \":\")[[-8..-5]]\t        , \":\"\t    )\t) & \":aaaa:bbbb:cccc:dddd\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":80,"wires":[["27b0461078c8496e"]]},{"id":"27b0461078c8496e","type":"debug","z":"452103ea51141731","name":"debug 91","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":80,"wires":[]}]

ah ok,
but I need to apply it to the internal IP, not from nslookup, it comes without disturbing strings just a payload::

2002:de:b72e:9200:dea6:10ef:fe23:be11

Then feed it that string, the output should be the same.

nope: invaild jsonata
Argument 1 of function "split" does not match function signature"

I just need:

2002:de:b72e:9200:dea6:10ef:fe23:be11

to -> 2002:de:b72e:9200

or

2002:de84:b72e:92:dea6:10ef:fe23:be11

to -> 2002:de84:b72e:92

Not a lot to go on.
What is the payload?
What did you paste in the change node?

Did my example flow work?

payload:

2002:de84:b72e:92:dea6:10ef:fe23:be11

or

2002:de:b72e:92ae:dea6:10ef:fe23:be11

I wish to have only the previx
**** : **** : **** : ****

don´t need to add something.

You have said that 3 times, i get it, that is what my expression does.
Now if you can show the payload you feed and what exactly you pasted in the change node, we could figure out why it is not working for you, as the below example works.

[{"id":"80f3a3ecc746e5e6","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2a00:60:b02d:1a04:11:32ff:fd48:eb43","payloadType":"str","x":250,"y":100,"wires":[["80898fe14df9b252"]]},{"id":"80898fe14df9b252","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$trim(\t    $join(\t        $split($$.payload, \":\")[[-8..-5]]\t        , \":\"\t    )\t) ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":80,"wires":[["27b0461078c8496e"]]},{"id":"27b0461078c8496e","type":"debug","z":"452103ea51141731","name":"debug 91","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":80,"wires":[]}]

If you don't need to add the aaaa:bbbbb:.... delete the & "aaaa:bbbb..."

[edit] Here is how to get all with one expression.

[{"id":"80898fe14df9b252","type":"change","z":"452103ea51141731","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"($bits := $split($$.payload, \":\").$trim();\t{\t    \"original\": $join($bits[[-8..-1]], \":\"),\t    \"prefix\":  $join($bits[[-8..-5]], \":\"),\t    \"static\":  $join($bits[[-8..-5]], \":\") & \":aaaa:bbbb:cccc:dddd\",\t    \"static_var\":  $join($bits[[-8..-5]], \":\") & $$.topic\t}\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":80,"wires":[["27b0461078c8496e"]]},{"id":"80f3a3ecc746e5e6","type":"inject","z":"452103ea51141731","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":":dddd:cccc:bbbb:aaaa","payload":"Server:\t\t127.0.0.1 Address:\t127.0.0.1#53  Non-authoritative answer: Name:\tmydomain.dynv6.net Address: 2a00:6020:b02d:1a04:11:32ff:fd48:eb43","payloadType":"str","x":250,"y":100,"wires":[["80898fe14df9b252"]]},{"id":"27b0461078c8496e","type":"debug","z":"452103ea51141731","name":"debug 91","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":680,"y":80,"wires":[]}]
1 Like

sorry @E1cid I have connected the wrong node :confounded:
your expression works