Re: Design idea for Ping Application

Discussion in 'Python' started by Mike C. Fletcher, Aug 19, 2003.

  1. Jeremy Hylton wrote:
    ....

    >Years ago I wrote ping in Python. I don't have the code anymore, but
    >there's not too much too it. One of the Stevens books has C source for
    >a simple ping, and it's not much work to adapt the basic design to
    >Python. It's far simpler than the C code.
    >
    >If you had a simple ping library in Python, it would be easy to run
    >several Ping instances in a single select loop. Then you don't need to
    >bother with threads and pipes and shells.
    >
    >

    As pointed out by a previous poster, it's available from Python.org.
    We've got a version which fixes a few (trivial) bugs (use of 'h'
    instead of 'H' in struct formats mostly, to indicate unsigned rather
    than signed ints). Works nicely on Win32, however, I've not yet been
    able to get the code to run under Unix (where creating raw sockets is a
    no-no).

    Our particular usage for it is (similar to the OP) as a component in a
    network monitoring application where fallback cases want to check a few
    hundred or thousand hosts on a local network to see if failures are
    occuring at the transport level or something higher. We use a custom
    asynchronous loop to keep ~ 100 requests in play simultaneously w/out
    any threading or process-spawning at all.

    Would love to hear from anyone who's doing ping on Unix and getting
    around the raw-socket restriction...

    It's alive! It's alive!
    Mike

    BTW, if people care (and Jeremy's okay with it), I'd be happy to package
    up Jeremy's tar in a disutils package (with bug-fixes) and create a
    sourceforge project for it (in my ever so copious free time :) ) so the
    code can continue to live a happy and productive life.

    _______________________________________
    Mike C. Fletcher
    Designer, VR Plumber, Coder
    http://members.rogers.com/mcfletch/
    Mike C. Fletcher, Aug 19, 2003
    #1
    1. Advertising

  2. David M. Cooke wrote:

    >At some point, "Mike C. Fletcher" <> wrote:
    >
    >

    ....

    >>however, I've not yet been
    >>able to get the code to run under Unix (where creating raw sockets is
    >>a no-no).
    >>
    >>

    >
    >Only root can create raw sockets. You'll notice the system ping
    >command is setuid root so that ordinary users can use it. Running this
    >code as root works.
    >
    >

    Yes, that's where I'd arrived too (only root can do it). I was sort of hoping there was some way around this silliness by using, e.g. non-raw sockets, or registering a socket as being ICMP-protocol and thereby letting the system check it's data for bad formatting/evil-stuff.

    I really don't like the idea of requiring a setuid setup just to allow a multi-ping module to work (it's not even a module at that point, it's got to be its own script/process, which means creating input and output formats and all that jazz rather than just reporting the results as data-structures). Multi-pinging is a trivial task, it's just a slightly more useful version of ping, but the root-user-requirment makes it a serious pain to implement.

    I mean, this is simple networking code using a well-established protocol (ICMP). Would be really nice to be able to say "hey, I'm interested in sending (raw) IP messages" without having to fundamentally restructure an application. Price of multi-user systems I suppose.

    Oh well, bite the bullet and make it a setuid-safe program and figure out how to get that installed on client machines. Or just scrap the whole direct approach on Unix and spawn 100 "ping" processes simultaneously.

    Thanks for confirming my fears. I'll never go out of the house again :) ,
    Mike

    _______________________________________
    Mike C. Fletcher
    Designer, VR Plumber, Coder
    http://members.rogers.com/mcfletch/
    Mike C. Fletcher, Aug 20, 2003
    #2
    1. Advertising

  3. At some point, "Mike C. Fletcher" <> wrote:
    > David M. Cooke wrote:
    >>At some point, "Mike C. Fletcher" <> wrote:
    >>

    > ...
    >
    >>>however, I've not yet been
    >>>able to get the code to run under Unix (where creating raw sockets is
    >>>a no-no).
    >>>

    >>
    >>Only root can create raw sockets. You'll notice the system ping
    >>command is setuid root so that ordinary users can use it. Running this
    >>code as root works.
    >>

    > ...
    > Oh well, bite the bullet and make it a setuid-safe program and
    > figure out how to get that installed on client machines. Or just
    > scrap the whole direct approach on Unix and spawn 100 "ping"
    > processes simultaneously.


    Problem there is there are different versions of ping. There are three
    versions available for Debian, for instance. With Redhat 7.x, the
    times are returned as microseconds, whereas others return
    milliseconds. The ping on Solaris, IIRC, by default just checks if a
    system is up. So you end up trying to figure out what version of ping
    you have, and how to call it correctly.

    --
    |>|\/|<
    /--------------------------------------------------------------------------\
    |David M. Cooke
    |cookedm(at)physics(dot)mcmaster(dot)ca
    David M. Cooke, Aug 22, 2003
    #3
    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. Andrew Dalke

    Re: Design idea for Ping Application

    Andrew Dalke, Aug 19, 2003, in forum: Python
    Replies:
    1
    Views:
    401
  2. Replies:
    10
    Views:
    1,234
    Big K
    Feb 2, 2005
  3. =?Utf-8?B?UGF1bA==?=
    Replies:
    2
    Views:
    348
    =?Utf-8?B?UGF1bA==?=
    Apr 17, 2007
  4. Dr Mephesto

    App idea, Any idea on implementation?

    Dr Mephesto, Feb 4, 2008, in forum: Python
    Replies:
    3
    Views:
    714
    Dennis Lee Bieber
    Feb 5, 2008
  5. Replies:
    0
    Views:
    632
Loading...

Share This Page