-
Notifications
You must be signed in to change notification settings - Fork 2
/
userips.py
42 lines (30 loc) · 1.09 KB
/
userips.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import znc
import collections
class userips(znc.Module):
module_types = [znc.CModInfo.GlobalModule]
description = "Shows IP addresses of connected users"
def WebRequiresAdmin(self):
return True
def GetWebMenuTitle(self):
return "User IPs"
def OnWebRequest(self, sock, page, tmpl):
users = znc.CZNC.Get().GetUserMap()
ordered_users = collections.OrderedDict(sorted(users.items()))
user_count = 0
connection_count = 0
for user in ordered_users.items():
row = tmpl.AddRow("UserLoop")
row["User"] = user[0]
user_clients = user[1].GetAllClients()
ip_string = ''
if user_clients:
user_count += 1
for client in user_clients:
ip_string += client.GetRemoteIP() + ' '
connection_count += 1
row["IP"] = ip_string
row = tmpl.AddRow("UserLoop")
row["User"] = "Total"
row["IP"] = str(user_count) + " users from "\
+ str(connection_count) + " connections"
return True