How do I tell LWP to use ipv4 and not ipv6?

Background that might be useful: I have a script that grabs data from our website. Using something like

my $ua = LWP::UserAgent->new; print "Setting Responce" if $debug; print "Why does it hang here for 2min" if $debug; my $response = $ua->request(GET 'https://ourcopanyswebsite.com/xorl/sc +ript147.php'); print "retrieving content\n" if $debug; my $returned_info = $response->content; # do stuff to returned_info and set $useful_data from it print $useful_data;

It works but there's a 120 second delay (and it is always 120 seconds) where the comment asks why does it hang here.

I have noticed if I on the command line do: wget https://ourcopanyswebsite.com/xorl/script147.php

that there is a similar long delay However if I do wget --inet4-only https://ourcopanyswebsite.com/xorl/script147.php it works fine with no delay.

While I am curious about the delay, some of the useful data I'm trying to get is the IPv4 address of the server running the script and the remote site will send the IPv6 address instead if it goes over that. So I really want to force IPv4 on LWP instead of figuring out the cause of the delay. If relevant, the server it is running on is Ubuntu 22.04.3 LTS.

Update: Corion's solution works: Adding before the request $ua->local_address("10.0.0.107") works.


In reply to LWP and ipv4 by xorl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.