I am perl beginner and under a situation where i have a dongle (USB internet key). When USB is connected and i do :

$address='Net::Address::IP::Local'->public ;

then it works fine and return an IP address. But i have situation where i have to check disconnect the USB and then check it's IP address using same code but on disconnection it gives an error on writing this command and it is:

Unable to create UDP socket: A socket operation was attempted to an un +reachable network. at C:/Perl/site/lib/Net/Address/IP/Local.pm line 166.

Yes ofcourse it will give error because it will not return any IP address when disconnected. But i wann handle this error. And assign a static IP when it is disconnected like "192.80.13.1". I tried to handle this error this way but out of success:

sub ReturnIpAddress { if( 'Net::Address::IP::Local'->public =~ m/^(\d\d?\d?)\.(\d\d?\d?)\. +(\d\d?\d?)\.(\d\d?\d?)$/ ) { return $address= 'Net::Address::IP::Local'->public; #When i try to + print this address it print nothing s it crashes because of the erro +r due to the enteres command i discussed before. } else { return $address='192.80.160.16'; } }

How to handle this error and assign statically $address='192.80.160.16' when USB key is disconnected ?


In reply to Why 'Net::Address::IP::Local'->public do not return IP address by ppp

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.