I (still ...) strongly suspect that you are seeing the error-message because of print $@;. Therefore, I specifically suggest that you should modify the if/else structure in more or less this way:
if ($@) {
print STDERR "An exception was caught!\n";
# (set the default IP-address here, etc ...)
} else {
print STDERR "An exception did not occur.\n"
# ( grab the real address here)
}
print STDERR "... so the IP-address is $ipaddr\n";
# (etc. etc ...)
In other words, cause the code to explicitly log what it’s doing, one way or the other, to remove all doubt as to what it
is doing.