Community discussions

MikroTik App
 
rzto
just joined
Topic Author
Posts: 4
Joined: Thu Jan 28, 2021 2:09 am

get ipaddress from ping command and store it in a variable

Sat Feb 13, 2021 5:56 pm

I'm trying to write a ddns update script that deals with ip addresses. I need to store into a local variable the ipaddress from the output of the ping command like
/ping google.com count=1
SEQ HOST                                     SIZE TTL TIME  STATUS                        
    0 216.58.204.142                             56 113 45ms
    sent=1 received=1 packet-loss=0% min-rtt=45ms avg-rtt=45ms max-rtt=45ms
I understand that the script should look something like
:local ipaddress [/ping google.com count=1]
but I'm newbie and I don;t know how to parse the output into a variable.
Help will be very much appreciated.
 
User avatar
che
Member Candidate
Member Candidate
Posts: 111
Joined: Fri Oct 07, 2005 1:04 pm

Re: get ipaddress from ping command and store it in a variable  [SOLVED]

Sat Feb 13, 2021 6:35 pm

Hi rzto, "ping" command is not used for resolving domains. You should go with "resolve", for example:
:local ipaddress [:resolve google.com]
 
rzto
just joined
Topic Author
Posts: 4
Joined: Thu Jan 28, 2021 2:09 am

Re: get ipaddress from ping command and store it in a variable

Sat Feb 13, 2021 7:57 pm

Che,
thanks very much for the answer and the solution.
Since my post I've learned that as well, however you were faster!
What a rookie mistake on my behalf at 64!
Thanks again.
PS How do I mark the topic SOLVED?

Who is online

Users browsing this forum: diamuxin, dredex and 22 guests