########################################################################
#
#  Copyright (C) 2009, CZ.NIC, z.s.p.o.
# 
#  This file is part of dnstester.
#
#  dnstester is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  dnstester is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
########################################################################

import mac, hostip, dns

class NetworkInfo:
    addresses = None
    addresses_log = None
    nameservers = None

    mac = None
    gw = None
    mac_log = None
    
    def __init__(self):
        
        (self.gw, self.mac), self.mac_log = mac.get_gateway_ipmac()
        self.addresses, self.addresses_log = hostip.host_addresses()

        resolver = dns.resolver.Resolver()
        self.nameservers = resolver.nameservers

    def get_data(self):

        val_addresses = ''
        if self.addresses: val_addresses = ', '.join(self.addresses)

        val_addresses_log = ''
        if self.addresses_log: val_addresses_log = self.addresses_log

        val_nameservers = ''
        if self.nameservers: val_nameservers = ', '.join(self.nameservers)

        val_mac = ''
        if self.mac: val_mac = self.mac

        val_gw = ''
        if self.gw: val_gw = self.gw

        val_mac_log = ''
        if self.mac_log: val_mac_log = self.mac_log

        return {
            'addresses': val_addresses,
            'addresses_log': val_addresses_log,
            'nameservers': val_nameservers,
            'mac': val_mac,
            'gateway': val_gw,
            'mac_log': val_mac_log,
            }


