473,857 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Beginner Ping program

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
7 6547
In <11************ *********@u30g2 000hsc.googlegr oups.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
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
In <11************ *********@n59g2 000hsh.googlegr oups.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
On Apr 27, 10:54 pm, Linus Cohen <l...@fixedstar s.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
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
En Sun, 29 Apr 2007 08:26:36 -0300, Bjoern Schliessmann
<us************ **************@ spamgourmet.com 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
Apr 29 '07 #7
"pe********@gma il.com" <pe********@gma il.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7779
by: bernd wegener | last post by:
Hello netties, I coded the following in perl: open(LOGFILE,">&STDOUT") ; if ( $ARGV ) { close(LOGFILE) ; open(LOGFILE,">> $ARGV") or die "Cannot open file $ARGV\n" ;
14
42906
by: Egil Hansen | last post by:
Hi I'm wondering if its possible to write a javascript, that can ping a ip and return the average round trip time (like ping in dos/linux)? Regards, Egil.
17
18231
by: wana | last post by:
I was reading through original source code of ping for some insight and was confused by unusual code. Entire listing available at: http://www.ping127001.com/pingpage/ping.html #include #include #include #include #include #include #include #include #include #include #include #include
0
7794
by: Ed | last post by:
I've attached some VB.NET code I've hacked together (some taken from MS examples & newsgroup postings) that will perform a ping or IcmpSendEcho using the icmp.dll (see this for more info: http://support.microsoft.com/default.aspx?scid=kb;en-us;170591 ). The problem I have is in order to perform a discovery/ping of an entire subnet (192.168.1.* for instance) I have to do a FOR loop to itterate through all of the addresses. That it seems...
3
1789
by: Rodney Garland | last post by:
Hi All, I am a relative beginner to Python and am looking for help with sending and XML message and getting back a return file. The server is: https://node.deq.state.or.us/node/node.asmx I have have successfully sent and recieved using the PING, AUTHENTICATE (send in username and password and return a secuirity token), SOLICIT(send in information for a query and get a number indicating the query),
21
30569
by: Neel | last post by:
I am trying to "ping" a remote host in my C++/Redhat Linux code to check whether that host is connected or not. if (0 == system("ping -w 2 192.168.0.2)) But, in both cases (connected/disconnected), system call returns 0. Can someone please show what I am doing wrong? How to check the actual result of the ping status using C++ on Redhat linux ? Thanks in advance.
15
4210
by: JohnDriver | last post by:
Hello I am learning Ajax and I am following the tutorials found but for some reason, my code is not working. I think I am missing something in the code that I am posting below. Please have a look and let me know. <html> <head> <script> function submitForm() { var test;
0
1297
by: Nick Stinemates | last post by:
On Tue, Apr 15, 2008 at 07:24:05AM -0700, shawn s wrote: I love that you call the users of your app retards :) That rocks! ping runs forever. tracert doesnt. try: -- Nick Stinemates (nick@stinemates.org)
1
1830
by: Karl Kobata | last post by:
Hi Fredrik, This is exactly what I need. Thank you. I would like to do one additional function. I am not using the tokenizer to parse python code. It happens to work very well for my application. However, I would like either or both of the following variance: 1) I would like to add 2 other characters as comment designation 2) write a module that can readline, modify the line as required, and finally, this module can be used as the...
0
9923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9767
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11082
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10394
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9549
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5774
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5967
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4190
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.