Howto get the PTR record for a single IP?

Folks,

I’m looking for pretty obvious need: getting the PTR (string) for an IP address in my script.

For example: having “18.196.34.14” in a variable, and I want to get it’s PTR (name): “ec2-18-196-34-14.eu-central-1.compute.amazonaws.com.
(even if it’s a non-authoritative answer)

How can I do it with scripts? Or I shall use an external online service for this?

Try the :resolve command

Exemple :

[admin@MikroTik] > :put [:resolve 18.196.34.14]
ec2-18-196-34-14.eu-central-1.compute.amazonaws.com

To use it in the script

:local ptr  [:resolve 18.196.34.14]

This will resolve the IP and save it to the variable ptr

OMG, thank you.
(I read a lot of old post and by that time this was unsupported)

Thank you! How can I make sure to not crash my script if I give it some invalid address? Like:

:local ptr  [:resolve 192.168.88.100]

?

I just have to put it into “:do” ?

You can use

on-error



:do {
	:local ptr  [:resolve 192.168.88.100]
	:put $ptr
} on-error={
	:put "Could not resolve"
}