detecting if I am connected to a ISP

Discussion in 'Ruby' started by Brett S Hallett, Oct 11, 2003.

  1. 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.
     
    Brett S Hallett, Oct 11, 2003
    #1
    1. Advertising

  2. Samuel Tesla <> wrote in message news:<>...
    > Brett S Hallett <> writes:
    >
    > > has actually connected to their ISP before running
    > > the program, natually I recieve a 'system error.

    >
    > 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.
     
    Lothar Scholz, Oct 12, 2003
    #2
    1. Advertising

  3. --=-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:
    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--
     
    Farrel Lifson, Oct 12, 2003
    #3
  4. Brett S Hallett

    JoeSeeder Guest

    Farrel Lifson wrote:
    >[..] I would run ifconfig and then parse [..]


    you don't have to call external apps, you can parse /proc/net/dev
     
    JoeSeeder, Oct 12, 2003
    #4
  5. In article <-ass.net>, JoeSeeder wrote:
    > Farrel Lifson wrote:
    >>[..] 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.
     
    Jason Williams, Oct 12, 2003
    #5
  6. Brett S Hallett

    daz Guest

    "Jason Williams" <> wrote:
    > In article <-ass.net>, JoeSeeder wrote:
    > > Farrel Lifson wrote:
    > >>[..] 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
     
    daz, Oct 12, 2003
    #6
  7. 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
     
    Dennis Oelkers, Oct 14, 2003
    #7
  8. On 11 Oct 2003 17:08:17 -0700,
    Lothar Scholz <> wrote:
    > 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.)
     
    Rob Partington, Oct 21, 2003
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luuk Postuma

    Deployment problems with ISP

    Luuk Postuma, Oct 21, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    341
    Elliot M. Rodriguez
    Oct 21, 2003
  2. JerryK

    ISP recommendation

    JerryK, Nov 5, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    336
    Steve
    Nov 5, 2003
  3. James X. Li
    Replies:
    1
    Views:
    407
    Jerry Boone
    Jan 2, 2004
  4. Guy
    Replies:
    1
    Views:
    678
    Jonck
    Sep 27, 2004
  5. Frances Del Rio

    detecting if a user is connected to the internet...

    Frances Del Rio, Oct 13, 2004, in forum: Javascript
    Replies:
    2
    Views:
    115
Loading...

Share This Page