How can I retrieve IP address from host?

Hi,
I am trying to obtain an IP address from a host. The available Ping nodes does not seem to return the IP address, so I tried the EXEC node with the following command:

nslookup myhost.com

This worked, but the object returned is not well formatted, so I could not extract the IP address easily.
The complete msg object looks like this:

{"_msgid":"ef79c141.ca169","payload":"Address:\t11.22.33.44:53\n\nNon-authoritative answer:\nNon-authoritative answer:\nName:\tmyhost.com\nAddress: 11.22.33.44\n\n"}

I appreciate if anyone could point me in the right direction. I just need the ip address from this whole message.

You could (in a function node) use a regular expression or the string split method.

Thanks @Steve-Mcl, but I am trying to keep it simple.
I tried the following EXEC command and it seems to work so far:

getent hosts myhost.com | awk '{ print $1 }'

The message payload contains the IP address only, which is what I wanted.

That wasn't your question though, you asked...

Hey ho, all well that ends well.

If you are making less than 1,000 calls per month, you could use a free https://geo.ipify.org/docs account.
I've used them for years, and very reliable.

A GET call; https://geo.ipify.org/api/v1?apiKey=at_EHuas86RK4ujhduhsdssffb0JF9&domain=bbc.co.uk

returns a payload.ip of "151.101.0.81" plus lots of other information if you need/want it.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.