import utmp from UTMPCONST import * import netifaces import os class DiscoverUsers: def __init__(self): self.IP=self.get_ip() #def __init__ def get_ip(self): for item in netifaces.interfaces(): tmp=netifaces.ifaddresses(item) if tmp.has_key(netifaces.AF_INET): if tmp[netifaces.AF_INET][0].has_key("broadcast") and tmp[netifaces.AF_INET][0]["broadcast"]=="10.0.2.255": return tmp[netifaces.AF_INET][0]["addr"] #def get_ip def discover(self): a = utmp.UtmpRecord(WTMP_FILE) user_list={} while 1: b = a.getutent() if not b: break if b[0] == USER_PROCESS: if os.path.exists("/proc/"+str(b.ut_pid)): if "tty" in b.ut_line: tty=b.ut_line.split("tty")[1] if tty >=7: user_list[b.ut_user]=self.IP elif b.ut_line=="": user_list[b.ut_user]=b.ut_host a.endutent() #Making sure i see everyone a = utmp.UtmpRecord() while 1: b = a.getutent() if not b: break if b[0] == USER_PROCESS: if os.path.exists("/proc/"+str(b.ut_pid)): if "tty" in b.ut_line: tty=b.ut_line.split("tty")[1] if tty >=7: user_list[b.ut_user]=self.IP elif b.ut_line=="": user_list[b.ut_user]=b.ut_host a.endutent() return user_list #def discover