pinging from within python

M

M.N.A.Smadi

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
 
J

Jorgen Grahn

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]
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
 
H

Harlin Seritt

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
 

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

Forum statistics

Threads
474,264
Messages
2,571,319
Members
48,003
Latest member
coldDuece

Latest Threads

Top