-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicecast-list-clients.py3
executable file
·114 lines (87 loc) · 2.9 KB
/
icecast-list-clients.py3
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/usr/bin/env python3
import xml.etree.ElementTree as ET
import urllib3
import base64
from termcolor import colored
from dns import resolver,reversename,exception
import sys
#import warnings
#warnings.filterwarnings("ignore", category=DeprecationWarning)
listeners_url="http://FIXME:8000/admin/listclients?mount=/FIXME"
stats_url="http://FIXME:8000/admin/stats?mount=/FIXME"
username = "admin"
password = "FIXME"
userpass = (username + ":" + password)
http = urllib3.PoolManager()
# Listeners
try:
headers = urllib3.util.make_headers(basic_auth=userpass)
listeners_request = http.request('GET', listeners_url, headers=headers)
except urllib3.exceptions.HTTPError as e:
print('Request failed:', e.reason)
# Stats
try:
headers = urllib3.util.make_headers(basic_auth=userpass)
stats_request = http.request('GET', stats_url, headers=headers)
except urllib3.exceptions.HTTPError as e:
print('Request failed:', e.reason)
listeners_data = listeners_request.data
stats_data = stats_request.data
listeners_root = ET.fromstring(listeners_data)
stats_root = ET.fromstring(stats_data)
# Init lists
ips=list()
ipv4=list()
ipv6=list()
uas=list()
connected=list()
title=list()
peak=list()
# Listeners
for child in listeners_root.iterfind('.//IP'):
ips.append(child.text)
if ":" in child.text:
ipv6.append(child.text)
else:
ipv4.append(child.text)
listeners=len(ips)
ipv4s=len(ipv4)
ipv6s=len(ipv6)
for child in listeners_root.iterfind('.//UserAgent'):
uas.append(child.text)
for child in listeners_root.iterfind('.//Connected'):
connected.append(child.text)
# Stats
for child in stats_root.iterfind('.//title'):
title.append(child.text)
for child in stats_root.iterfind('.//listener_peak'):
peak.append(child.text)
print ("")
ctitle = colored(title[0], 'magenta')
clisteners = colored(listeners, 'green')
cpeak = colored(peak[0], 'green')
print ("Now playing:", ctitle)
print ("")
print ("Current listeners: %-2s (%s ipv4, %s ipv6)" % (clisteners,ipv4s,ipv6s))
print ("Peak listeners: %-2s" % (cpeak))
print ("-------------------------------------------------------------------------------------------------------------------------------")
for i in range(0, listeners):
cips = colored(ips[i], 'cyan')
cuas = colored(uas[i], 'yellow')
cconnected = colored(connected[i], 'magenta')
addr=reversename.from_address(ips[i])
try:
answer = str(resolver.resolve(addr,"PTR")[0])
answer = answer.rstrip('.')
rdns = colored(answer, 'blue')
except resolver.NXDOMAIN:
rdns = colored("NO RDNS", 'blue')
except resolver.Timeout:
rdns = colored("NO RDNS", 'blue')
except exception.DNSException:
rdns = colored("NO RDNS", 'blue')
print ('IP: %-48s Connected for (seconds): %-6s' % (cips,cconnected))
print ('RDNS: %-75s' % (rdns))
print ('User agent: %-75s' % (cuas))
print ("-------------------------------------------------------------------------------------------------------------------------------")
print("")