How to get geo info from your Shoutcast listeners

How to get geo info from your Shoutcast listeners

I wrote a quick and dirty python script to list listeners of a Shoutcast stream and display their location information. This allows me to see who’s listening, and give them a shout-out while doing live broadcasts.

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
#!/usr/bin/python
import urllib2
import json

url = "http://myshoutcastserver.com:9283/admin.cgi?sid=1&mode=viewjson&pass=mypassword"
results = urllib2.urlopen(url).read()
data  = json.loads(results)

print "\nHawkwynd Radio Current listeners"
print "--------------------------------\n"

for i in data['listeners']:
   
    hostname = i['hostname']
    locUrl = "http://ipinfo.io/"+hostname+"/json"
    res = urllib2.urlopen(locUrl).read()  
    pak = json.loads(res)
   
    # calculate time online
    millis = int(i['connecttime']*1000)
    seconds = (millis/1000)%60
    seconds = int(seconds)
    minutes = (millis/(1000*60))%60
    minutes = int(minutes)
    hours = (millis/(1000*60*60))%24
   
    if pak['region'] == '':
        pak['region']='Unknown Region'

    print pak['ip'] + "\t" + pak['city'] , pak['region'] +", " + pak['country'] + " connected: " + ("%d:%d:%d" % (hours, minutes, seconds))
   

print "\n"

Which displays:

1
2
3
Current listeners
-----------------
54.174.143.164  Virginia Beach Virginia, US connected: 0:32:57