I am under a situation where i am trying to get the current IP address with time. The code below works fine when there is connection of internet and it return the IP as desired.

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

The problem is my code also has to run if there is No internet connection, so the problem occurs when i am disconnected and still run the same code it breaks my all code because there is no IP written by it as we are disconnected from internet

Now i have though some solution of it but out of luck!!!! The solution is wheni receive no IP address then i should assign a static IP address like this ($address='192.80.160.16';) But it do not work. My try to do it is below :

sub ReturnIpAddress { select STDOUT; my $address = 'Net::Address::IP::Local'->public ; ## Receiving the c +urrent IP ## if(!$address) { return $address='192.80.160.16'; ##If No IP address received then +return a static IP of order "192....." } else { return $address; } }

But it still do not work. When i try to print that IP adress on disconnect then it prints nothing (If it was like Null or 0 in c++ i could have handle it but i dont know how to handle it by doing something like this (if($address==null){ $address='192.80.160.16';}) in case of perl)

Any help please ?


In reply to How to handle Net::Address::IP::Local'->public when we are not connected to internet 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.