import BeautifulSoup as bs
import urllib3
URL = "https://zeustracker.abuse.ch/monitor.php"


def zeus_tracker_ips(url):
    '''

    :param url:
    :return A list of Lists (20x2) : IP Address, Rank :
    '''
    spamlist = []
    http = urllib3.PoolManager()
    doc = http.request('GET', url).data

    soup = bs.BeautifulSoup(doc)


    soup = soup.findAll('table')[1]

    for row in soup.findAll('tr'):

        aux = row.findAll('td')

        if len(aux) > 1 and aux[2].find('a'):
            spam = {}

            spam['palevo_tracker'] = "0"
            spam['feodo_tracker'] = "0"
            spam['spyeye_tracker'] = "0"
            spam['zeus_tracker'] = "1"
            if aux[1].string:

                spam['description_text'] = 'Malware : ' + aux[1].string


            spam['host_name'] = aux[2].find('a').string
            if aux[3].find('a'):
                spam['ip_address'] = aux[3].find('a').string
            spam['listing_date'] = aux[0].string
            if aux[9].find('a'):
                spam['autonomous_system_number'] = aux[9].find('a').string
            #spam['autonomous_system_name'] = aux[6].string

            if aux[8].find('img'):
                spam['country'] = spam['country'] = aux[8].find('img')['title']

            #print spam
            spamlist.append(spam)

    return spamlist


zeus_tracker_ips(URL)