Ping monitor - monitor ip in the background?

ScottZ mylists at pinesalad.net
Sat Nov 1 23:26:43 EDT 2008


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? 




More information about the Python-list mailing list