Пример #1
0
 def getBridgePage(self):
     # Get the bridge page for applicable radios.
     # Data is a big JSON.
     data = self.getStatusPage('brmacs.cgi?brmacs=y&_=' +\
         Toolbox.timestamp())
     brm = data['brmacs']
     bridges = {}
     # The last element is always null.
     datum = data.pop()
     while datum:
         try:
             # Attempt to look it up from the existing bridges.
             bridge = bridges[datum['bridge']]
             bridge['interfaces'].add(datum['port'])
             bridge['macs'].add(datum['hwaddr'])
         except KeyError:
             # If the bridge is unknown, initialize it.
             bridge = {}
             # Sets for deduplication.
             bridge['interfaces'] = set(datum['port'])
             bridge['macs'] = set(datum['hwaddr'])
             bridges.append(bridge)
         bridge = {}
         bridges[datum['bridge']] = {}
         datum = data.pop()
     return bridges
Пример #2
0
 def getInterfacePage(self):
     # Get the list of network interfaces from the web interface.
     data = self.getStatusPage('iflist.cgi?_=' + str(Toolbox.timestamp()))
     interfaces = {}
     if interfaces:
         for ifdata in data['interfaces']:
             interface = {}
             try:
                 # The typing is for consistency with the SNMP data.
                 interfaces[Mac(ifdata['hwaddr'])] = set([Ip(ifdata['ipv4']['addr'])])
             except KeyError:
                 # Some interfaces won't have an address.
                 pass
     return interfaces
Пример #3
0
    def arpCrawl(self, timestamp=Toolbox.timestamp()):
        host = self.hosts
        def scan(host):
            # Update the timestamp.
            host.touch()
            # If we can't get a hostname, nothing else is going to work.
            print('Scanning host...', end=' ')
            if host.scanHostname():
                print(host.hostname)
                print('Scanning interfaces...', end=' ')
                host.scanInterfaces()
                host.print()

                print(len(host.addresses), 'interfaces discovered.')
                if not host.vendor == 'ubiquiti':
                    print('Scanning ARP...', end=' ')
                    arps = host.scanArpTable()
                    print(len(arps), 'arp records discovered.')
                #host.print()
                host.scanLocation()
                print('Host located at:', host.location, 'coords:', host.coords)
                print('Host\'s new timestamp:', host.updated)
                print('There are', len(self.nodes()), 'nodes.')
                print('Of which', len([a for a in self.nodes() if type(a) == Host]), 'are hosts.')
                print('Of which', len([a for a in self.nodes() if type(a) == Host\
                    and a.hostname == 'AwbreyM20']), 'are AwbreyM20.')
            else:
                print('Scan failed at', host.ips)
        hosts = self.hosts
        # Sort the list so that the least recently updated is last.
        for host in hosts:
            # Continuously scan the entire network.
            # Take the oldest entry.
            scan(host)
            #nx.draw(self, nx.spring_layout(self), node_size=3, node_color='yellow', font_size=6)
            #plt.tight_layout()
            #plt.savefig('graph.png', format='PNG')

            # Write safely
            nx.write_gml(self, 'network.gml.tmp', stringizer=Toolbox.stringize)
            os.rename('network.gml.tmp', 'network.gml')
            hosts += [h for h in self.hosts if h.updated < timestamp]
Пример #4
0
 def touch(self):
     # Update timestamp on host.
     self.network.node[self]['updated'] = Toolbox.timestamp()