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

I tried the code below but still it gives error :
use strict; use warnings; use Net::Address::IP::Local; print ReturnIpAddress(); sub ReturnIpAddress { my $address; 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; } }
error is :
Unable to create UDP socket: A socket operation was attempted to an un +reachab network. at C:/Perl/site/lib/Net/Address/IP/Local.pm line 166.
  • Comment on Re^2: How to handle Net::Address::IP::Local'->public when we are not connected to internet (INADDR_ANY)
  • Select or Download Code

Replies are listed 'Best First'.
Re^3: How to handle Net::Address::IP::Local'->public when we are not connected to internet (INADDR_ANY)
by Laurent_R (Canon) on Jan 19, 2015 at 18:54 UTC
    In the post you included in your other thread on the same subject, the output you gave showed the socket error and then the printed IP address, so that it appears that this part of your code is working properly, your program non longer dies on the error and is able to print the IP address after the socket open failure.

    Je suis Charlie.