widget.setKeyAndValue( "last 5 minutes", {"packets": rs.pop("lastFiveMinsPkts", ""), "bytes": rs.pop("lastFiveMinsBytes", "")}, ) if len(rs) > 0: widget.setKeyAndValue("other", rs) # ==================================== # Top Hosts by Throughput Widget Data # ==================================== if widgetId.lower() == "tophoststhroughput": topHosts = [] while ntop.getNextHost(i): if ( len(search) > 0 and host.hostResolvedName().lower().find(search.lower()) == -1 and host.ethAddress().lower().find(search.lower()) == -1 and host.ipAddress().lower().find(search.lower()) == -1 ): continue if host.ipAddress() == "": # drop host with no throughput or no ip continue geo = host.geoIP() country = geo.get("country_name", "") countryCode = geo.get("country_code", "") hostType = ( 0 + __P2P__ * host.isP2P() + __VOIP__ * (host.isVoIPHost() | host.isVoIPClient() | host.isVoIPGateway()) + __PRINTER__ * host.isPrinter() + __DIRECTORY__ * host.isDirectoryHost()
'last 5 minutes', { 'packets': rs.pop('lastFiveMinsPkts', ''), 'bytes': rs.pop('lastFiveMinsBytes', '') }) if (len(rs) > 0): widget.setKeyAndValue('other', rs) # ==================================== # Top Hosts by Throughput Widget Data # ==================================== if (widgetId.lower() == "tophoststhroughput"): topHosts = [] while ntop.getNextHost(i): if (len(search) > 0 and host.hostResolvedName().lower().find( search.lower()) == -1 and host.ethAddress().lower().find(search.lower()) == -1 and host.ipAddress().lower().find( search.lower()) == -1): continue if host.ipAddress() == "": #drop host with no throughput or no ip continue geo = host.geoIP() country = geo.get('country_name', '') countryCode = geo.get('country_code', '') hostType = 0 + __P2P__ * host.isP2P() + __VOIP__ * ( host.isVoIPHost() | host.isVoIPClient() | host.isVoIPGateway()) + __PRINTER__ * host.isPrinter( ) + __DIRECTORY__ * host.isDirectoryHost( ) + __WORKSTATION__ * host.isWorkstation( ) + __HTTPHOST__ * host.isHTTPhost(
# Top hosts for which interface? selectedif = form.getvalue('if', default="") ifIndex = identify_interface_index(selectedif) while ntop.getNextHost(ifIndex): if host.ipAddress() == "": #drop host with no throughput or no ip continue #host.hostResolvedName() #ntop.sendString("%s\n" % host.hostResolvedName()) #ip,mac,name,fingerprint,isFTPhost,isWorkstation,isMasterBrowser,isPrinter,isSMTPhost,isPOPhost,isIMAPhost,isDirectoryHost,isHTTPhost,isVoIPClient,isVoIPGateway,isDHCPServer,isDHCPClient, data = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" % ( host.ipAddress(), host.ethAddress(), host.hostResolvedName(), host.fingerprint(), host.isFTPhost(), host.isWorkstation(), host.isMasterBrowser(), host.isPrinter(), host.isSMTPhost(), host.isPOPhost(), host.isIMAPhost(), host.isDirectoryHost(), host.isHTTPhost(), host.isVoIPClient(), host.isVoIPGateway(), host.isDHCPServer(), host.isDHCPClient()) ntop.sendString("%s\n" % data) ''' while ntop.getNextHost(interfaceId): #ip,mac,name,fingerprint,isFTPhost,isWorkstation,isMasterBrowser,isPrinter,isSMTPhost,isPOPhost,isIMAPhost,isDirectoryHost,isHTTPhost,isVoIPClient,isVoIPGateway,isDHCPServer,isDHCPClient, data = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" % (host.ipAddress(), host.ethAddress(), host.hostResolvedName(), host.fingerprint(), host.isFTPhost(),host.isWorkstation(),host.isMasterBrowser(),host.isPrinter(), host.isSMTPhost(),host.isPOPhost(),host.isIMAPhost(),host.isDirectoryHost(),host.isHTTPhost(), host.isVoIPClient(),host.isVoIPGateway(),host.isDHCPServer(),host.isDHCPClient()) ntop.sendString("%s\n" % data)
# to kbytes bytesSent = host.bytesSent()/1000 bytesRcvd = host.bytesRcvd()/1000 bytes = bytesSent if (direction == 1): bytes = bytesRcvd packetsSent = host.pktSent() packetsRcvd = host.pktRcvd() packets = packetsSent if (direction == 1): packets = packetsRcvd #INSERT into the list using the bisect costs only O(logN) # might be cpu consuming insort_rightReversed(topHostsByPeakThroughput, (thpPeak, {'hostname':host.hostResolvedName(),'macaddress':host.ethAddress(),'hardware':host.hwModel(), 'type':hostType, 'ip':host.ipAddress(), 'up':thpPeakSent, 'down':thpPeakRcvd, 'country':countryCode, 'direction':direction})) insort_rightReversed(topHostsByAverageThroughput, (thpAvg, {'hostname':host.hostResolvedName(),'macaddress':host.ethAddress(),'hardware':host.hwModel(), 'type':hostType, 'ip':host.ipAddress(), 'up':thpAvgSent, 'down':thpAvgRcvd, 'country':countryCode, 'direction':direction})) insort_rightReversed(topHostsByActualThroughput, (thpPeak, {'hostname':host.hostResolvedName(),'macaddress':host.ethAddress(),'hardware':host.hwModel(), 'type':hostType, 'ip':host.ipAddress(), 'up':thpActSent, 'down':thpActRcvd, 'country':countryCode, 'direction':direction})) insort_rightReversed(topHostsByTransferedBytes, (bytes, {'hostname':host.hostResolvedName(),'macaddress':host.ethAddress(),'hardware':host.hwModel(), 'type':hostType, 'ip':host.ipAddress(), 'up':bytesSent, 'down':bytesRcvd, 'country':countryCode, 'direction':direction})) insort_rightReversed(topHostsByTransferedPackets, (packets, {'hostname':host.hostResolvedName(),'macaddress':host.ethAddress(),'hardware':host.hwModel(), 'type':hostType, 'ip':host.ipAddress(), 'up':packetsSent, 'down':packetsRcvd, 'country':countryCode, 'direction':direction})) # cut lists if len(topHostsByPeakThroughput)>topN and topN>0: topHostsByPeakThroughput=topHostsByPeakThroughput[:topN] if len(topHostsByAverageThroughput)>topN and topN>0: topHostsByAverageThroughput=topHostsByAverageThroughput[:topN] if len(topHostsByActualThroughput)>topN and topN>0: topHostsByActualThroughput=topHostsByActualThroughput[:topN] if len(topHostsByTransferedBytes)>topN and topN>0: topHostsByTransferedBytes=topHostsByTransferedBytes[:topN]
form = cgi.FieldStorage(); # Top hosts for which interface? selectedif = form.getvalue('if', default="") ifIndex = identify_interface_index(selectedif) while ntop.getNextHost(ifIndex): if host.ipAddress()=="": #drop host with no throughput or no ip continue #host.hostResolvedName() #ntop.sendString("%s\n" % host.hostResolvedName()) #ip,mac,name,fingerprint,isFTPhost,isWorkstation,isMasterBrowser,isPrinter,isSMTPhost,isPOPhost,isIMAPhost,isDirectoryHost,isHTTPhost,isVoIPClient,isVoIPGateway,isDHCPServer,isDHCPClient, data = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" % (host.ipAddress(), host.ethAddress(), host.hostResolvedName(), host.fingerprint(), host.isFTPhost(),host.isWorkstation(),host.isMasterBrowser(),host.isPrinter(), host.isSMTPhost(),host.isPOPhost(),host.isIMAPhost(),host.isDirectoryHost(),host.isHTTPhost(), host.isVoIPClient(),host.isVoIPGateway(),host.isDHCPServer(),host.isDHCPClient()) ntop.sendString("%s\n" % data) ''' while ntop.getNextHost(interfaceId): #ip,mac,name,fingerprint,isFTPhost,isWorkstation,isMasterBrowser,isPrinter,isSMTPhost,isPOPhost,isIMAPhost,isDirectoryHost,isHTTPhost,isVoIPClient,isVoIPGateway,isDHCPServer,isDHCPClient, data = "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s" % (host.ipAddress(), host.ethAddress(), host.hostResolvedName(), host.fingerprint(), host.isFTPhost(),host.isWorkstation(),host.isMasterBrowser(),host.isPrinter(), host.isSMTPhost(),host.isPOPhost(),host.isIMAPhost(),host.isDirectoryHost(),host.isHTTPhost(), host.isVoIPClient(),host.isVoIPGateway(),host.isDHCPServer(),host.isDHCPClient()) ntop.sendString("%s\n" % data) '''