# Query IP address from url

**URL:** <https://discourse.nodered.org/t/query-ip-address-from-url/69356>\
**Category:** General\
**Created:** [21 October 2022 05:41 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356 "2022-10-21T05:41:55Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 05:41 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/1 "2022-10-21T05:41:55Z")

</div>

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](https://gist.github.com/corny/7a07f5ac901844bd20c9) looks only to the internal stored IP, it don´t query the stored IPv6 in dynv6.

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 05:52 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/2 "2022-10-21T05:52:01Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 October 2022 07:48 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/3 "2022-10-21T07:48:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 10:18 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/4 "2022-10-21T10:18:14Z")

</div>

it is the payload from debug

![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/873f27ac83ce1ffeec2d0a1479725f3320d480f6.png)

```auto
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 ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 October 2022 10:44 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/5 "2022-10-21T10:44:04Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 15:23 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/6 "2022-10-21T15:23:14Z")

</div>

I got it:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d0f3a38bc50ae12e976b99224ded17ed87a72718.png)

🤓 👍

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

---

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)\
**Post date:** [21 October 2022 16:13 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/7 "2022-10-21T16:13:02Z")

</div>

> [@Colin](#):
>
> Probably it could also be done with a clever regular expression.

Or with a simple jsonata expression in change node:

- [https://try.jsonata.org/ISKFPz00e](https://try.jsonata.org/ISKFPz00e)

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

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 17:21 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/8 "2022-10-21T17:21:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![janvda](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/janvda/32/234_2.png) [@janvda](https://discourse.nodered.org/u/janvda)\
**Post date:** [21 October 2022 17:56 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/9 "2022-10-21T17:56:30Z")

</div>

> [@Becker](#):
>
> 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)

See:

- [https://try.jsonata.org/j6rZH53VY](https://try.jsonata.org/j6rZH53VY)

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

```auto
payload~>$substring(0,19)

```

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

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 20:09 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/10 "2022-10-21T20:09:23Z")

</div>

> [@janvda](#):
>
> `(payload~>$split(/Address:/))[2]~>$trim()`

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 ":" ?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 October 2022 20:49 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/11 "2022-10-21T20:49:34Z")

</div>

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

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

```

output

```auto
2a00:6020:b02d:1a04:aaaa:bbbb:cccc:dddd

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 20:52 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/12 "2022-10-21T20:52:39Z")

</div>

but where can I paste this jasonata ? 🤔

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 October 2022 20:55 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/13 "2022-10-21T20:55:45Z")

</div>

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

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 21:01 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/14 "2022-10-21T21:01:42Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 October 2022 21:03 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/15 "2022-10-21T21:03:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 21:06 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/16 "2022-10-21T21:06:04Z")

</div>

> [@E1cid](#):
>
> ```auto
> $split($.payload, ":")[[-8..-5]]
> , ":"
> 
> ```

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

I just need:

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

```

to -\> 2002:de:b72e:9200

or

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

```

to -\> 2002:de84:b72e:92

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 October 2022 21:09 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/17 "2022-10-21T21:09:09Z")

</div>

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

Did my example flow work?

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 21:11 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/18 "2022-10-21T21:11:56Z")

</div>

payload:

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

```

or

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

```

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

don´t need to add something.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [21 October 2022 21:15 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/19 "2022-10-21T21:15:40Z")

</div>

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.

```auto
[{"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.

```auto
[{"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":[]}]

```

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [21 October 2022 21:20 UTC](https://discourse.nodered.org/t/query-ip-address-from-url/69356/20 "2022-10-21T21:20:26Z")

</div>

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

[Next page](https://discourse.nodered.org/t/query-ip-address-from-url/69356.md?page=2)
