Beginner Ping program

L

Linus Cohen

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
 
M

Marc 'BlackJack' Rintsch

Linus Cohen said:
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
 
L

Linus Cohen

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
 
M

Marc 'BlackJack' Rintsch

Linus Cohen said:
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
 
P

petercable

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
 
B

Bjoern Schliessmann

Linus said:
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
 
G

Gabriel Genellina

En Sun, 29 Apr 2007 08:26:36 -0300, Bjoern Schliessmann
IIRC, MS ping has no "never stop", you can only say "repeat 99999
times".

ping -t hostname
 

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,990
Messages
2,570,211
Members
46,796
Latest member
SteveBreed

Latest Threads

Top