Line | |
---|
1 | import utmp |
---|
2 | from UTMPCONST import * |
---|
3 | import netifaces |
---|
4 | import os |
---|
5 | |
---|
6 | class DiscoverUsers: |
---|
7 | |
---|
8 | def __init__(self): |
---|
9 | |
---|
10 | self.IP=self.get_ip() |
---|
11 | |
---|
12 | #def __init__ |
---|
13 | |
---|
14 | def get_ip(self): |
---|
15 | |
---|
16 | for item in netifaces.interfaces(): |
---|
17 | tmp=netifaces.ifaddresses(item) |
---|
18 | if tmp.has_key(netifaces.AF_INET): |
---|
19 | if tmp[netifaces.AF_INET][0].has_key("broadcast") and tmp[netifaces.AF_INET][0]["broadcast"]=="10.0.2.255": |
---|
20 | return tmp[netifaces.AF_INET][0]["addr"] |
---|
21 | |
---|
22 | #def get_ip |
---|
23 | |
---|
24 | def discover(self): |
---|
25 | |
---|
26 | a = utmp.UtmpRecord(WTMP_FILE) |
---|
27 | user_list={} |
---|
28 | |
---|
29 | while 1: |
---|
30 | b = a.getutent() |
---|
31 | if not b: |
---|
32 | break |
---|
33 | if b[0] == USER_PROCESS: |
---|
34 | if os.path.exists("/proc/"+str(b.ut_pid)): |
---|
35 | if "tty" in b.ut_line: |
---|
36 | tty=b.ut_line.split("tty")[1] |
---|
37 | if tty >=7: |
---|
38 | user_list[b.ut_user]=self.IP |
---|
39 | |
---|
40 | elif b.ut_line=="": |
---|
41 | user_list[b.ut_user]=b.ut_host |
---|
42 | |
---|
43 | |
---|
44 | a.endutent() |
---|
45 | |
---|
46 | #Making sure i see everyone |
---|
47 | a = utmp.UtmpRecord() |
---|
48 | |
---|
49 | while 1: |
---|
50 | b = a.getutent() |
---|
51 | if not b: |
---|
52 | break |
---|
53 | if b[0] == USER_PROCESS: |
---|
54 | if os.path.exists("/proc/"+str(b.ut_pid)): |
---|
55 | if "tty" in b.ut_line: |
---|
56 | tty=b.ut_line.split("tty")[1] |
---|
57 | if tty >=7: |
---|
58 | user_list[b.ut_user]=self.IP |
---|
59 | |
---|
60 | elif b.ut_line=="": |
---|
61 | user_list[b.ut_user]=b.ut_host |
---|
62 | |
---|
63 | |
---|
64 | a.endutent() |
---|
65 | |
---|
66 | |
---|
67 | return user_list |
---|
68 | |
---|
69 | #def discover |
---|
Note: See
TracBrowser
for help on using the repository browser.