Beginner Ping program

Discussion in 'Python' started by Linus Cohen, Apr 28, 2007.

  1. Linus Cohen

    Linus Cohen Guest

    Hi all,
    I'm a newbie to python and programming in general, so I wanted a
    simple project to start off. What I'm trying to do here is write a
    python command-line ping program, much like the Unix and Windows ping
    programs. I've got this much worked out already:

    class ping
    def PING(IP, pings, size):

    and that's where I stop, because I realize I have no idea how to make
    python send ICMP request packets. My previous project(an email reader
    using poplib)used the stuff in section 18 of the modules
    index(internet protocols) but I can't seem to find an equivalent for
    ICMP packets. If anyone has help on this, I would really appreciate
    it.

    Cheers,
    Linus
    Linus Cohen, Apr 28, 2007
    #1
    1. Advertising

  2. In <>, Linus Cohen
    wrote:

    > I'm a newbie to python and programming in general, so I wanted a
    > simple project to start off. What I'm trying to do here is write a
    > python command-line ping program, much like the Unix and Windows ping
    > programs. I've got this much worked out already:
    >
    > class ping
    > def PING(IP, pings, size):


    Why is it a class? I would have expected a `ping()` function.

    And you might have a look at `PEP 8 -- Style Guide for Python Code`_ for
    spelling conventions for class and function names.

    ... _PEP 8 -- Style Guide for Python Code:
    http://www.python.org/dev/peps/pep-0008/

    Ciao,
    Marc 'BlackJack' Rintsch
    Marc 'BlackJack' Rintsch, Apr 28, 2007
    #2
    1. Advertising

  3. Linus Cohen

    Linus Cohen Guest

    Actually the class ping bit is a placeholder. I'm actually developing
    a module with python implementations of most standard network/internet
    tools such as telnet, tracert, whois etc. It will be called inettools,
    and the ping function is what I'm working on first. It should be a
    simple enough job to code in the features the Unix and DOS ping
    programs have(never stop, change size, change timeout).
    As I am typing this, I'm looking through ping.c to see what I can
    glean. It probably won't be much. My experience with C is very little.
    As in, microscopic. Pretty much all the coding I've done up till now
    has been shell scripting.

    Cheers,
    Linus
    Linus Cohen, Apr 28, 2007
    #3
  4. In <>, Linus Cohen
    wrote:

    > Actually the class ping bit is a placeholder. I'm actually developing
    > a module with python implementations of most standard network/internet
    > tools such as telnet, tracert, whois etc. It will be called inettools,
    > and the ping function is what I'm working on first.


    Still doesn't explain why it is a class.

    Ciao,
    Marc 'BlackJack' Rintsch
    Marc 'BlackJack' Rintsch, Apr 28, 2007
    #4
  5. Linus Cohen

    Guest

    On Apr 27, 10:54 pm, Linus Cohen <> wrote:
    > Hi all,
    > I'm a newbie to python and programming in general, so I wanted a
    > simple project to start off. What I'm trying to do here is write a
    > python command-line ping program, much like the Unix and Windows ping
    > programs. I've got this much worked out already:
    >
    > class ping
    > def PING(IP, pings, size):


    I agree with Marc here, probably no reason for a class here. As well,
    if you are creating classes, generally class names should be
    capitalized, methods should be lower case, i.e.

    class Ping(object):
    def ping(self, ip, pings, size):
    ....

    But, there really is no need for a class here, placeholder or
    otherwise.

    >
    > and that's where I stop, because I realize I have no idea how to make
    > python send ICMP request packets. My previous project(an email reader
    > using poplib)used the stuff in section 18 of the modules
    > index(internet protocols) but I can't seem to find an equivalent for
    > ICMP packets. If anyone has help on this, I would really appreciate
    > it.


    There is no (that I am aware of) ICMP module in the standard library.
    See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/409689 for
    an example of a Python implementation of ping.

    >
    > Cheers,
    > Linus


    HTH,

    Pete
    , Apr 28, 2007
    #5
  6. Linus Cohen wrote:

    > Actually the class ping bit is a placeholder.


    But why is it one? "ping" is something you do -- and not a "thing"
    of which you could have several copies.

    > I'm actually developing a module with python implementations of
    > most standard network/internet tools such as telnet, tracert,
    > whois etc. It will be called inettools, and the ping function is
    > what I'm working on first. It should be a simple enough job to
    > code in the features the Unix and DOS ping programs have(never
    > stop, change size, change timeout).


    IIRC, MS ping has no "never stop", you can only say "repeat 99999
    times".

    Regards,


    Björn

    --
    BOFH excuse #148:

    Insert coin for new game
    Bjoern Schliessmann, Apr 29, 2007
    #6
  7. En Sun, 29 Apr 2007 08:26:36 -0300, Bjoern Schliessmann
    <> escribió:

    > Linus Cohen wrote:
    >> It will be called inettools, and the ping function is
    >> what I'm working on first. It should be a simple enough job to
    >> code in the features the Unix and DOS ping programs have(never
    >> stop, change size, change timeout).

    >
    > IIRC, MS ping has no "never stop", you can only say "repeat 99999
    > times".


    ping -t hostname

    --
    Gabriel Genellina
    Gabriel Genellina, Apr 29, 2007
    #7
  8. Linus Cohen

    Duncan Booth Guest

    Duncan Booth, Apr 30, 2007
    #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. bernd wegener

    Piping ping into perl-prog

    bernd wegener, Sep 15, 2004, in forum: Perl
    Replies:
    3
    Views:
    642
    Jim Gibson
    Sep 22, 2004
  2. =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=

    No Class at ALL!!! beginner/beginner question

    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=, Feb 2, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    551
    =?Utf-8?B?S3VydCBTY2hyb2VkZXI=?=
    Feb 3, 2005
  3. Rensjuh
    Replies:
    7
    Views:
    940
    Mabden
    Sep 2, 2004
  4. william nelson

    Beginner's Beginner

    william nelson, Apr 11, 2011, in forum: Ruby
    Replies:
    7
    Views:
    191
    7stud --
    Apr 12, 2011
  5. Egil Hansen

    A ping program in javascript?

    Egil Hansen, Jul 19, 2005, in forum: Javascript
    Replies:
    14
    Views:
    368
    Egil Hansen
    Jul 25, 2005
Loading...

Share This Page