Ping monitor - monitor ip in the background?

2008-11-01 Thread ScottZ

With python 2.6 and wxpython I'm trying to create a system tray icon
application based around an example found here:
http://codeboje.de/MailSneaker-Part-3-SystemTrayTaskBar-Icons-with-Python-and-wxPython/

The application will simply change the systray icon based on if an ip
address is online or not.

The ping portion looks like this:

if os.name == "nt":  # Windows
pcmd = "ping -n 1 -w 1000 "
else:# *nix
pcmd = "ping -c1 -W1 "

def Ping(ipaddress):
# execute the code and pipe the result to a string
p = subprocess.Popen(pcmd + ipaddress, shell=True,
stdout=subprocess.PIPE)
# give it time to respond
p.wait()

a = re.search('(.*)ms', p.stdout.read())
if a:
return True
else:
return False

I've been able to add the ping check as a manual process (via a right
click menu item) but very confused on what direction to take on making
the ping a permanent loop while the app is running. 

I was looking at making the ping routine a thread process but can't
figure out how to feed back the result to the calling app. Global
variable??

Ideas? 

--
http://mail.python.org/mailman/listinfo/python-list


RE: Ping monitor - monitor ip in the background?

2008-11-02 Thread ScottZ

Andrey - Thank you very much for the example.
Is something missing after the def start(self): or should def run(): not
be there?
I think I understand the idea your showing though and working on
adapting it.
Again thanks!

Jorgen - yes that is very true in regards to the *nix comment.
I will change that comment to "for my *nix environment" to be more
precise in the future.

It was posted as an example of what I'm doing rather than a global ping
solution for all.
I deploy an alternative set of common tools (ping being one of them)
amongst our various platforms so the options in this case isn't an issue
for me.

A built in ping method would be better was being looked into but wanted
to get this part finished first. 

Thanks


 

 Original Message 
Subject: Re: Ping monitor - monitor ip in the background?
From: Jorgen Grahn <[EMAIL PROTECTED]>
Date: Sun, November 02, 2008 1:04 am
To: [email protected]

On Sat, 01 Nov 2008 20:26:43 -0700, ScottZ <[EMAIL PROTECTED]>
wrote:
...
> if os.name == "nt": # Windows
> pcmd = "ping -n 1 -w 1000 "
> else: # *nix
> pcmd = "ping -c1 -W1 "

Not really correct. Unfortunately there are many variants of ping for
Unix, and they don't take the same flags. In Solaris, for example, -c
is not a count, and -W doesn't seem to exist at all.

If I recall correctly, you can't even count on Linux installations to
have compatible pings.

Too bad that you cannot easily implement ping in your program -- it
needs extra privileges in order to handle ICMP.

/Jorgen

-- 
 // Jorgen Grahn  R'lyeh wgah'nagl fhtagn!
--
http://mail.python.org/mailman/listinfo/python-list



--
http://mail.python.org/mailman/listinfo/python-list