示例#1
0
     widget.setKeyAndValue("peak", {"packets": rs.pop("peakPkts", ""), "bytes": rs.pop("peakBytes", "")})
     widget.setKeyAndValue(
         "last minute", {"packets": rs.pop("lastMinPkts", ""), "bytes": rs.pop("lastMinBytes", "")}
     )
     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
示例#2
0
             'packets': rs.pop('lastMinPkts', ''),
             'bytes': rs.pop('lastMinBytes', '')
         })
     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()
示例#3
0
ifIndex = identify_interface_index(selectedif)

topHostsByPeakThroughputMetadata = {'type':'updowntable','mode':'gauge','unit':'kbps','title':'Top Hosts by Throughput Peak'}
topHostsByAverageThroughputMetadata = {'type':'updowntable','mode':'gauge','unit':'kbps','title':'Top Hosts by Throughput Average'}
topHostsByActualThroughputMetadata = {'type':'updowntable','mode':'gauge','unit':'kbps','title':'Top Hosts by Actual Throughput'}
topHostsByTransferedBytesMetadata = {'type':'updowntable','mode':'counter','unit':'kB','title':'Top Hosts by Bytes'}
topHostsByTransferedPacketsMetadata = {'type':'updowntable','mode':'counter','unit':'packets','title':'Top Hosts by Packet Number'}

topHostsByPeakThroughputData = {}
topHostsByAverageThroughputData = {}
topHostsByActualThroughputData = {}
topHostsByTransferedBytesData = {}
topHostsByTransferedPacketsData = {}

while ntop.getNextHost(ifIndex):
	
	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() + __FTPHOST__*host.isFTPhost() + __SERVER__*host.isServer() + __MAILSERVER__*(host.isSMTPhost()|host.isPOPhost()|host.isIMAPhost()) + __DHCP__*(host.isDHCPClient()|host.isDHCPServer())

	thpSent=host.sendThpt()
	thpRcvd=host.receiveThpt()
	
	# set peak throughput
	# according to direction ( kBps )
示例#4
0
__WORKSTATION__ = 32
__HTTPHOST__ = 64
__FTPHOST__ = 128
__SERVER__ = 256
__MAILSERVER__ = 512
__DHCP__ = 1024

# form management
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)
 
 totalHosts = 0
 unknownCountries = 0
 unknownCities = 0
 flag = 's'                                  # s (default) for sent packets r for received, b for both
 SIXDECIMAL = decimal.Decimal(10) ** -6      # decimals are all fixed to 6 es. 0.000000
 
 # Parse URL
 cgitb.enable();
 
 form = cgi.FieldStorage();
 
 if form.getvalue('OP') == 'Change':
     flag = form.getvalue('countHosts', 's')
 
 while ntop.getNextHost(0):
     totalHosts += 1
     geo = host.geoIP()
     
     countryCode = geo.get('country_code', '')
     countryName = geo.get('country_name', '')
     city = geo.get('city', '')
     
     lat = str(geo.get('latitude', '0.000000'))
     lon = str(geo.get('longitude', '0.000000'))
     
     latitude = decimal.Decimal(lat).quantize(SIXDECIMAL)
     longitude = decimal.Decimal(lon).quantize(SIXDECIMAL)
     
     if not countryCode or countryCode == 'EU' or countryCode == 'AP' :      # the country was not found therefore the city was not found, everything in the object is set accordingly
         countryCode = ''
示例#6
0
    totalHosts = 0
    unknownCountries = 0
    unknownCities = 0
    flag = 's'  # s (default) for sent packets r for received, b for both
    SIXDECIMAL = decimal.Decimal(
        10)**-6  # decimals are all fixed to 6 es. 0.000000

    # Parse URL
    cgitb.enable()

    form = cgi.FieldStorage()

    if form.getvalue('OP') == 'Change':
        flag = form.getvalue('countHosts', 's')

    while ntop.getNextHost(0):
        totalHosts += 1
        geo = host.geoIP()

        countryCode = geo.get('country_code', '')
        countryName = geo.get('country_name', '')
        city = geo.get('city', '')

        lat = str(geo.get('latitude', '0.000000'))
        lon = str(geo.get('longitude', '0.000000'))

        latitude = decimal.Decimal(lat).quantize(SIXDECIMAL)
        longitude = decimal.Decimal(lon).quantize(SIXDECIMAL)

        if not countryCode or countryCode == 'EU' or countryCode == 'AP':  # the country was not found therefore the city was not found, everything in the object is set accordingly
            countryCode = ''