Determine connection status on Linux

S

Sisyphus

Hi,

Not entirely on-topic, I'm afraid, but how do I determine from a perl
script if I'm currently connected to the Internet ?

A system() command would be satisfactory, if I can just find out which
one to use :)

I'm having dificulty with Device::Modem - should I persevere ?

For making the connection manually, I use the kppp dialer on (Mandrake)
linux - which connects me through an external dialup modem.

Cheers,
Rob
 
D

David Efflandt

Hi,

Not entirely on-topic, I'm afraid, but how do I determine from a perl
script if I'm currently connected to the Internet ?

A system() command would be satisfactory, if I can just find out which
one to use :)

I'm having dificulty with Device::Modem - should I persevere ?

For making the connection manually, I use the kppp dialer on (Mandrake)
linux - which connects me through an external dialup modem.

#!/usr/bin/perl -w
if (system '/sbin/ifconfig ppp0 > /dev/null 2>&1') {
die "we are offline\n";
}
print "we are online\n";
# do something useful
 
D

David Efflandt

One other note is that if you specifically want to do something whenever
Linux pppd connects, do it from /etc/ppp/ip-up (or ip-up.local). This
runs whever pppd gets an IP address. But use full paths, because
environment is minimal (also note that anything there would run as root).
 
S

Sisyphus

David said:
One other note is that if you specifically want to do something whenever
Linux pppd connects, do it from /etc/ppp/ip-up (or ip-up.local). This
runs whever pppd gets an IP address. But use full paths, because
environment is minimal (also note that anything there would run as root).

Thanks David.

Cheers,
Rob
 
S

Sisyphus

David said:
#!/usr/bin/perl -w
if (system '/sbin/ifconfig ppp0 > /dev/null 2>&1') {
die "we are offline\n";
}
print "we are online\n";
# do something useful

And if offline, how to connect ?
I didn't ask initialy because I thought I had the answer to that with:
system 'kppp -c account';
but that command, while it establishes and keeps open a connection,
never exits. Put that in a perl script, and it never progresses beyond
that point.
I'm not so sure that's the expected behaviour of that system command - I
thought it *did* open the connection and exit the first time I ran it,
but it certainly won't now.

Anyway, thanks for any help on this.
(I've asked about this on the mandrake ng but they're being a little
slow to respond.)

Cheers,
Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top