Community discussions

MikroTik App
 
DyadyaGenya
Member Candidate
Member Candidate
Topic Author
Posts: 220
Joined: Mon May 08, 2023 10:34 pm

Parse data (ip adress) from a text file and from JSON.

Sun Nov 05, 2023 10:19 pm

There is such a site: wtfismyip.com, where you can conveniently get the address in a text file or json. I don’t know much about Linux (RouterOS is Linux after all) and I can’t figure out how to parse the IP address that this site gives out.
I found an example of saving the address to a file.
/tool fetch url="https://wtfismyip.com/text" mode=https dst-path=ip.txt
local ip [file get ip.txt contents ]
:put $ip
But I would not like to write something to the Mikrotik disk. I would like to immediately get a ready-made ip.
Moreover, I would like to have two options: from text and from json.
 
optio
Long time Member
Long time Member
Posts: 675
Joined: Mon Dec 26, 2022 2:57 pm

Re: Parse data (ip adress) from a text file and from JSON.  [SOLVED]

Mon Nov 06, 2023 12:54 am

:local ip ([/tool fetch url="https://wtfismyip.com/text" output=user as-value]->"data")
This output contains blanks, you can find script to strip it or you can use ipify.org which doesn't contains blanks in output text:
:local ip ([/tool fetch url="https://api.ipify.org" output=user as-value]->"data")
or you can get from JSON from wtfismyip.com without blanks but you need parser script like: https://github.com/Winand/mikrotik-json-parser.
 
DyadyaGenya
Member Candidate
Member Candidate
Topic Author
Posts: 220
Joined: Mon May 08, 2023 10:34 pm

Re: Parse data (ip adress) from a text file and from JSON.

Mon Nov 06, 2023 1:53 pm

or you can get from JSON from wtfismyip.com without blanks but you need parser script like: https://github.com/Winand/mikrotik-json-parser.
Thank you, I was just planning to start working on scripts again closer to the New Year, and in particular parsing json. Now I will know what to focus on.
you can find script to strip it or you can use ipify.org which doesn't contains blanks in output text:
:local ip ([/tool fetch url="https://api.ipify.org" output=user as-value]->"data")
Special thanks for this site and code. Before this, I could not find a site where the address is obtained separately (in a file, in json, or something else)

Who is online

Users browsing this forum: No registered users and 9 guests