Thanks for that hint.
I now use IO::Interface to get my local ppp0 ip-address:
use IO::Socket;
use IO::Interface qw(:flags);
sub get_local_addr {
my $if = shift;
my $s = IO::Socket::INET->new(Proto => 'udp');
unless ($s->if_flags($if) & IFF_RUNNING) {
return undef;
} else {
return $s->if_addr($if);
}
}
and then in my script I test, if the ip-address of the ppp0 interface changed:
use Net::Ping;
my $addr = get_local_addr("ppp0");
unless(defined $addr) {
die "I'm offline\n";
}
while (1) {
my $p = Net::Ping->new(udp);
if $p->ping($host) {
print "success\n";
} else {
print "failed\n";
my $cur_addr = get_local_addr("ppp0");
if ($addr ne $cur_addr) {
die "I'm offline\n";
}
}
undef $p;
sleep 3;
}
There's no need to restart the script, because it will get started by my if-up script.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|