By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,172 Members | 727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,172 IT Pros & Developers. It's quick & easy.

Beginner Ping program

P: n/a
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

Apr 28 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
In <11*********************@u30g2000hsc.googlegroups. com>, 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
Apr 28 '07 #2

P: n/a
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

Apr 28 '07 #3

P: n/a
In <11*********************@n59g2000hsh.googlegroups. com>, 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
Apr 28 '07 #4

P: n/a
On Apr 27, 10:54 pm, Linus Cohen <l...@fixedstars.com.auwrote:
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/Coo.../Recipe/409689 for
an example of a Python implementation of ping.
>
Cheers,
Linus
HTH,

Pete

Apr 28 '07 #5

P: n/a
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

Apr 29 '07 #6

P: n/a
En Sun, 29 Apr 2007 08:26:36 -0300, Bjoern Schliessmann
<us**************************@spamgourmet.comescri bió:
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
Apr 29 '07 #7

P: n/a
"pe********@gmail.com" <pe********@gmail.comwrote:
There is no (that I am aware of) ICMP module in the standard library.
See http://aspn.activestate.com/ASPN/Coo.../Recipe/409689 for
an example of a Python implementation of ping.
Google also finds another implementation at:

http://www.gnist.org/~lars/code/ping/ping.py
Apr 30 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.