detecting if I am connected to a ISP

B

Brett S Hallett

Hi, I have written a small mail pre-viewer in Ruby/FXRuby which allows a
graphic view of incoming mail headers, from
which I can select canditates for deletion before loading,
I an using POP, however I cannot see any way to detect that the user
has actually connected to their ISP before running
the program, natually I recieve a 'system error.
 
L

Lothar Scholz

Samuel Tesla said:
Generally, if they aren't connected to the network, they'll get a
network unreachable error. So you could try something along the lines
of this (very untested) code:

begin
TCPSocket.new(mailserver, "pop-3")
rescue e => Errno::ENETUNREACH
puts "Are you connected?"
end

It's better to check for a high performance/high available site like
"www.google.com". If you can't reach them it's a network problem.
But this can popup a please connect window on Windows, which is not
desireable in periodic mail checks etc.
 
F

Farrel Lifson

--=-JN0i0JJe4wBLs49EwtO3
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable

I wrote a Ruby script that connected to my ISP a while ago. To test if I
was connected I would run ifconfig and then parse the first line
returned and look for 'ppp' (the name of the connection). This is a bit
hackish and I'm pretty sure there is a better way to do it.

Farrel
--=20
Data Network Architecture Research Lab mailto:[email protected]
Dept. of Computer Science http://people.cs.uct.ac.za/~flifs=
on
University of Cape Town +27-21-650-3127

--=-JN0i0JJe4wBLs49EwtO3
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)

iD8DBQA/iX7JGlar2y1bD7ARArcIAKC4jw6Ro0OYm8Kelh3ToHNJIEsyhACfa//E
yeTapXMo+8PHucB+eowhjjw=
=tWnM
-----END PGP SIGNATURE-----

--=-JN0i0JJe4wBLs49EwtO3--
 
J

Jason Williams

Farrel said:
[..] I would run ifconfig and then parse [..]

you don't have to call external apps, you can parse /proc/net/dev

The obvious problem with both of these solutions, of course, is that
you've shot any kind of portability through both kneecaps.
 
D

daz

Jason Williams said:
Farrel said:
[..] I would run ifconfig and then parse [..]

you don't have to call external apps, you can parse /proc/net/dev

The obvious problem with both of these solutions, of course, is that
you've shot any kind of portability through both kneecaps.

Made me chuckle, anyway <gg>.
---

## OMG!, What's this ?
## Non-production crufty hack-type example.

require 'socket'

ip = IPSocket.getaddress(Socket.gethostname)
print 'My guess is that you '
if ip == '127.0.0.1'
print 'are NOT'
else
print 'ARE'
end
puts ' connected at this time'


There may be an issue where a site has multiple IP addresses.
I've never seen what is returned in these situations --
(Array, comma separated String) ?
but if someone could post an example, there may be a general
solution someone could provide.

At least, it doesn't trigger the 'Do you want to connect?'
on Windows.


daz
 
D

Dennis Oelkers

In my opinion the only portable and secure way is just to connect to
the mailserver using socket calls while catching any exceptions.
The result of any other solution will not be predictable, and is in
no way sufficient to draw a conclusion about the state of a net
connection and even provokes race conditions.

If the problem is that this could make some "Do you want to dial-in?"
window pop up on some less-clued operating systems you could increase
your timer interval to a reasonable high number to prevent that from
happening too often.

Just my $0,02,
Dennis Oelkers
--
Dennis Oelkers | Webadministration | Zentraleinrichtung Rechenzentrum
TU-Berlin | EN-Gebaeude, K042 | Telefon: 030-314-25029

Key Fingerprint:
A6 7A B6 90 09 56 E8 32 02 40 6B 27 80 17 00 89 61 E7 CA 6F
 
R

Rob Partington

It's better to check for a high performance/high available site like
"www.google.com". If you can't reach them it's a network problem.

How is that better than trying to connect to the mail server and port
they're about to download mail from? If you can't get to it, it matters
not one jot whether you can get to google, you still can't get the mail.

(I can think of several reasons why someone might not be able to reach
google, but would be able to reach their mail server.)
 

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,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top