ppp has asked for the wisdom of the Perl Monks concerning the following question:
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 ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why 'Net::Address::IP::Local'->public do not return IP address
by Laurent_R (Canon) on Jan 16, 2015 at 18:31 UTC | |
by ppp (Acolyte) on Jan 16, 2015 at 18:56 UTC | |
by Laurent_R (Canon) on Jan 16, 2015 at 22:31 UTC | |
by Anonymous Monk on Jan 19, 2015 at 17:26 UTC | |
by Laurent_R (Canon) on Jan 19, 2015 at 18:39 UTC |