Community discussions

MikroTik App
 
danergo
Member Candidate
Member Candidate
Topic Author
Posts: 131
Joined: Tue Dec 24, 2019 8:49 pm

Howto get the PTR record for a single IP?

Thu Nov 25, 2021 12:22 pm

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?
 
ConnyMercier
Forum Veteran
Forum Veteran
Posts: 725
Joined: Tue Dec 17, 2019 1:08 pm

Re: Howto get the PTR record for a single IP?

Thu Nov 25, 2021 12:38 pm

Try the :resolve command

Exemple :

[admin@MikroTik] > :put [:resolve 18.196.34.14]
ec2-18-196-34-14.eu-central-1.compute.amazonaws.com
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Howto get the PTR record for a single IP?

Thu Nov 25, 2021 1:30 pm

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
 
danergo
Member Candidate
Member Candidate
Topic Author
Posts: 131
Joined: Tue Dec 24, 2019 8:49 pm

Re: Howto get the PTR record for a single IP?

Thu Nov 25, 2021 1:31 pm

OMG, thank you.
(I read a lot of old post and by that time this was unsupported)
 
danergo
Member Candidate
Member Candidate
Topic Author
Posts: 131
Joined: Tue Dec 24, 2019 8:49 pm

Re: Howto get the PTR record for a single IP?

Thu Nov 25, 2021 1:37 pm

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

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]
?
 
danergo
Member Candidate
Member Candidate
Topic Author
Posts: 131
Joined: Tue Dec 24, 2019 8:49 pm

Re: Howto get the PTR record for a single IP?

Thu Nov 25, 2021 1:44 pm

I just have to put it into ":do" ?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3297
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Howto get the PTR record for a single IP?

Thu Nov 25, 2021 7:52 pm

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

Who is online

Users browsing this forum: JDF, saied and 22 guests