python 2.7 - Raspberry PI - pinging multiple IPs -


would either code analysed , fixed or point me in right direction please. many errors, overcome, others not.

program runs on raspberry pi2 , should try , ping specific ip addresses , return result.

very new programming, can tell! not sure if need ping library or can without

import sys import time pushbullet import pushbullet import serial  class users(object):     def __init__(self, name=none, ip=none):         self.name = name         self.ip = ip         self.status = 'out' pb = pushbullet("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") #pushbullet id removed  userlist = [] userlist.append(users("ali", "192.18.1.14")) userlist.append(users("sophie", "192.18.1.9")) userlist.append(users("tv", "192.18.1.7"))  try:     while true:          print "checking... " + time.strftime("%a, %d %b %y %h:%m:%s", time.gmtime())         user in userlist:             result = os.system ("ping -n 1 " = user.ip)             oldstatus = user.status             if (result == 0):                     #what we'll if device detected                 if (oldstatus == 'out'):                     push = pb.push_note("home pi", user.name + " home")                     user.status = 'in'                 print user.name + " home"             else:                  #what we'll if device not not detected                 if (oldstatus == 'in'):                     push = pb.push_note("home pi", user.name + " has left")                     user.status = 'out'                 print user.name + " out"          print "next check in 30 seconds"         time.sleep(30)          except (keyboardinterrupt, systemexit): 

i modified code work, don't have pushbullet. compare new code previous see difference , errors

 import sys import time #from pushbullet import pushbullet #import serial #you need import os import os  class users(object):     def __init__(self, name=none, ip=none):         self.name = name         self.ip = ip         self.status = 'out' #pb = pushbullet("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") #pushbullet id removed  userlist = [] userlist.append(users("notebook", "192.168.1.2")) userlist.append(users("tv", "192.168.1.4"))  try:     while true:          print "checking... " + time.strftime("%a, %d %b %y %h:%m:%s", time.gmtime())         user in userlist:             #result = os.system ("ping -n 1 " = user.ip)         # concatenate string need + sign             #result = os.system("ping -n 1 " + user.ip)             # -n wrong option ubuntu             result = os.system("ping -c 1 " + user.ip)             oldstatus = user.status             if (result == 0):                     #what we'll if device detected                 if (oldstatus == 'out'):                     #push = pb.push_note("home pi", user.name + " home")                     user.status = 'in'                 print user.name + " home"             else:                  #what we'll if device not not detected                 if (oldstatus == 'in'):                     #push = pb.push_note("home pi", user.name + " has left")                     user.status = 'out'                 print user.name + " out"          print "next check in 30 seconds"         time.sleep(30)  #wrong identation except (keyboardinterrupt, systemexit):   sys.exit(0) 

Comments