in reply to How to handle Net::Address::IP::Local'->public when we are not connected to internet

When i try to print that IP adress on disconnect then it prints nothing

Did you check Net::Address::IP::Local::Error exception is thrown?


All is well
  • Comment on Re: How to handle Net::Address::IP::Local'->public when we are not connected to internet

Replies are listed 'Best First'.
Re^2: How to handle Net::Address::IP::Local'->public when we are not connected to internet
by ppp (Acolyte) on Jan 19, 2015 at 16:38 UTC
    Yes it gives some UDP socket connection couldnt created.. type of error. I dont have that in pc here. I saw in my school this morning. But error was linke some .. UDP socket cudnt create.. So how to handle it . I t gives this error because there is no internet access and even then i am trying to get IP , so no connection i guess thats why..

    But how i can handle it ? Because if i print it like this :

    print "adress is : 'Net::Address::IP::Local'->public";
    Then it just print:
    adress is :
    Now it even do not print 0 or null so that i could habdle it like this if($adress=null) {do this} How to handle ?

      Try the same with eval. Here is the code, I have added eval part

      use strict; use warnings; use Net::Address::IP::Local; print ReturnIpAddress(); sub ReturnIpAddress { select STDOUT; eval{ $address = 'Net::Address::IP::Local'->public ; ## Rece +iving the current IP ## }; if ($@) { print "$@"; return '192.80.160.16'; ##If No IP address received th +en return a static IP of order "192....." } else { return $address; } }

      All is well
        I got ur point.. all is well now .. Thnaks :)
        Same error :
        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. 192.80.160.16

      If you’re really doing this, and it’s not just a typo, it’s not what you think. Package and object stuff does not work as interpolated strings. Well, not without trickery. This–

      print "adress is : 'Net::Address::IP::Local'->public";

      –will print this–

      adress is : 'Net::Address::IP::Local'->public