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

pinging from within python

P: n/a
hi;

I need a simple script to run the ping command with some parameters and
be able to read the return value of the ping function. Any pointers will
be appreciated

thanks
m.smadi
Sep 11 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On 2005-09-11, M.N.A.Smadi <sm*****@grads.ece.mcmaster.ca> wrote:
I need a simple script to run the ping command with some parameters and
be able to read the return value of the ping function. Any pointers will
be appreciated


http://www.google.com/search?hl=en&q=python+ping

--
Grant Edwards grante Yow! I think my CAREER
at is RUINED!!
visi.com
Sep 11 '05 #2

P: n/a
Impacket module can helps you to construct the ip/icmp packet structure,
then you can send the packet and wait for the ECHOREPLY by using a
RAW_SOCKET.
Here's an example:
http://oss.coresecurity.com/impacket/ping.py

Cheers
I need a simple script to run the ping command with some parameters and be
able to read the return value of the ping function. Any pointers will be
appreciated

thanks
m.smadi

Sep 11 '05 #3

P: n/a
On Mon, 12 Sep 2005 01:36:35 +0200, billiejoex <bi********@fastwebnet.it> wrote:
Impacket module can helps you to construct the ip/icmp packet structure,
then you can send the packet and wait for the ECHOREPLY by using a
RAW_SOCKET.
Here's an example:
http://oss.coresecurity.com/impacket/ping.py


Yeah, but is he willing to be root, and ditch Windows, just to be able to
ping? Exec()ing the ping utility is often better, but beware -- different
pings take different options.

[the original poster]
I need a simple script to run the ping command with some parameters and be
able to read the return value of the ping function.


What is "the return value of the ping function"? You can use the ping
utility for many different things, and it reports many different kinds of
outcomes. It's not black and white.

/Jorgen

--
// Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu
\X/ algonet.se> R'lyeh wgah'nagl fhtagn!
Sep 17 '05 #4

P: n/a
You can do the following:

import os

data = os.popen('ping machineName').read()
if 'request timed out' in data or 'unknown host' in data:
Ping Failed Code
else:
Ping Returned Something Good Code

This is the quickest and really most effective way to get it done IMO.

Harlin Seritt
Internet Villa: www.seritt.org

Sep 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.