Accessing to ISP's modem with Scripting?

Hi folks!

I have a relative "complicated’ setup, am a noob with Mikrotik Scripting and want to know how to access to my modem to know their public IP.

With this code I get a HTML report with the IP:

curl -c /tmp/test --location --request POST 'http://192.168.1.1/login-login.cgi' --data-raw 'sessionKey=__&pass=__'
curl --location --request GET 'http://192.168.1.1/wancfg.cmd?action=view' -b /tmp/test

Will it be easy to do? Where should I start?

Thanks!

You can use the following alternative in RouterOS CLI or script:
:put [:resolve myip.opendns.com server=resolver1.opendns.com]

The above command prints your public IP, ie. that of your WAN link provided by your ISP.
You can put the result also into a variable, if needed.

In Linux or Windows you can use it as follows by using the “nslookup” command utility:
nslookup myip.opendns.com resolver1.opendns.com

In Windows you have maybe to use a slightly different syntax. See this man-page:
https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/nslookup

If you do use the MT cloud service you can use this command to get your public IP.

:put [/ip cloud get public-address]

Posted before…

Here are a few ways to get the public IP address

Pick IP From Route (add WAN to your WAN connection name. ie. ether1-WAN)
:global Stat [/ip route get [find gateway~“WAN”] pref-src]

Pick IP from Address (add WAN to your WAN connection name. ie. ether1-WAN)
:global OnEtherSub [/ip address get [find interface~“WAN”] address]
:global OnEther [:pick $OnEtherSub 0 [:find $OnEtherSub “/”]]

Pick IP from DHCP-Client (add WAN to your WAN connection name. ie. ether1-WAN)
:global OnEtherSub [/ip dhcp-client get [find interface~“WAN”] address]
:global OnEther [:pick $OnEtherSub 0 [:find $OnEtherSub “/”]]

Get Public IP from IP Cloud
:global ipCloud [/ip cloud get public-address]

Resolve your current DNS name
:global RESOLVED [:resolve something.whatever.com]