Community discussions

MikroTik App
 
Radek01
just joined
Topic Author
Posts: 18
Joined: Wed Mar 01, 2023 11:20 am

How to use fetch tool with IPv6

Tue Apr 23, 2024 4:20 pm

I'm solving a problem with the fetch tool. I am trying to send a request using the POST method to an HTTPS address that has both A and AAAA records on the DNS servers. For example:
/tool fetch url="https://api.wedos.com/" http-method=post http-data="{\"request\":{\"command\":\"ping\"}}" output=user-with-headers as-value]
Unfortunately, fetch is trying to connect over IPv4. How do I force fetch to connect over IPv6?
 
User avatar
baragoon
Member
Member
Posts: 315
Joined: Thu Jan 05, 2017 10:38 am
Location: Kyiv, UA
Contact:

Re: How to use fetch tool with IPv6

Tue Apr 23, 2024 6:12 pm

+1, I would like to know too
 
User avatar
Kentzo
Long time Member
Long time Member
Posts: 545
Joined: Mon Jan 27, 2014 3:35 pm
Location: California

Re: How to use fetch tool with IPv6

Wed Apr 24, 2024 12:05 am

Have you tried setting the src-address?
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1111
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: How to use fetch tool with IPv6

Wed Apr 24, 2024 12:37 am

@Radek01: The short answer is: you can't.

The reason is that ROS unfortunately lacks capabilities to control the dual-stack for embedded tools and services such as IPsec, WireGuard, DNS, IP Cloud, resolver, fetch, etc.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12033
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How to use fetch tool with IPv6

Wed Apr 24, 2024 1:18 pm

v6.48.7 working example code

{
    /ipv6 firewall address-list
    add address=api.myip.com list=api.myip.com
    :delay 2s
    :local ipv6add ([/ipv6 firewall address-list print as-value where comment="api.myip.com"]->0->"address")
    :set ipv6add [:pick $ipv6add 0 [:find $ipv6add "/" -1] ]
    :put [/tool fetch host=api.myip.com url="https://api.myip.com/index.php" output=user as-value]
    :put [/tool fetch host=api.myip.com url="https://$ipv6add/index.php" output=user as-value]
    remove [find where address=api.myip.com and list=api.myip.com]
}
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1111
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: How to use fetch tool with IPv6

Wed Apr 24, 2024 2:40 pm

Yeah, that's likely a functional but ugly workaround for a flawed dual-stack management. Let's hope MT will fix this eventually.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 12033
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: How to use fetch tool with IPv6

Wed Apr 24, 2024 2:42 pm

It was just meant to be a temporary solution...
Like the others that I have proposed over time and it took years to integrate them into RouterOS...
 
Radek01
just joined
Topic Author
Posts: 18
Joined: Wed Mar 01, 2023 11:20 am

Re: How to use fetch tool with IPv6

Wed Apr 24, 2024 3:35 pm

Thank you all for your replies. Unfortunately, I'm not pleased. I hope Mikrotik will fix it soon.

v6.48.7 working example code

I use RouterOS 7.14 and following row gives this error message "failure: Conflicting hostnames provided in URI and parameter":
:put [/tool fetch host=api.myip.com url="https://$ipv6add/index.php" output=user as-value]
Last edited by Radek01 on Thu Apr 25, 2024 9:41 am, edited 1 time in total.
 
optio
Long time Member
Long time Member
Posts: 698
Joined: Mon Dec 26, 2022 2:57 pm

Re: How to use fetch tool with IPv6

Wed Apr 24, 2024 9:27 pm

Try with
:put [/tool fetch url="http://$ipv6add/index.php" http-header-field="Host:api.myip.com" output=user as-value]
Note: use http protocol, https requires (E)SNI host name which is not set from URL when accesing over IP and SSL handshake will fail since certificate is not issued for IP. Also this will not work on web services which redirects http to https but api.myip.com is not doing that, unfortunately api.wedos.com (from OP) does and this trick cannot be used on that host.
 
Radek01
just joined
Topic Author
Posts: 18
Joined: Wed Mar 01, 2023 11:20 am

Re: How to use fetch tool with IPv6

Thu Apr 25, 2024 9:45 am

Exactly as you wrote, unusable for api.wedos.com because it also redirects to https. Thanks for the info.

Who is online

Users browsing this forum: GlebsK, Google [Bot] and 6 guests