예제 #1
0
def identify_interface_index(ifname):
    """Identifies the interface index for the given interface name.
	This is used in order to extract hosts from teh correct interface.
	if ifname is nil it returns 0
	"""
    if ifname == '': return 0

    for i in range(interface.numInterfaces()):
        if (interface.name(i).lower() == ifname.lower()):
            return i

    return 0
예제 #2
0
def identify_interface_index(ifname):
	"""Identifies the interface index for the given interface name.
	This is used in order to extract hosts from teh correct interface.
	if ifname is nil it returns 0
	"""
	if ifname == '': return 0
	
	for i in range(interface.numInterfaces()):
		if (interface.name(i).lower() == ifname.lower()):
			return i
			
	return 0
예제 #3
0
import sys

# form management
form = cgi.FieldStorage()

#instance.py?query=check&client='iphone'&version=<version>
# what king of query?
query = form.getvalue('query', default="")

# What type of client?
client = form.getvalue('client', default="")

# What version of client?
version = form.getvalue('version', default=0)
version = float(version)

data={}
if ('check' == query.lower()):
	data['check'] = version >= 1.0 and client.lower() == "iphone"

if ('interfaces' == query.lower()):
	interfaces = []
	for i in range(interface.numInterfaces()):
		interfaces.append(interface.uniqueName(i))
	data['interfaces'] = interfaces
if ('host' == query.lower()):
	data['host'] = {'version': ntop.version(),'os': ntop.os(),'uptime': ntop.uptime()}

ntop.sendHTTPHeader(1) # 1 = HTML
ntop.sendString(json.dumps(data, sort_keys=False, indent=4))
예제 #4
0
# Import modules for CGI handling
import cgi, cgitb
import ntop, interface, json

# Parse URL
cgitb.enable()

form = cgi.FieldStorage()
name = form.getvalue('Name', default="nubie")

version = ntop.version()
os = ntop.os()
uptime = ntop.uptime()

ifnames = []
try:
    for i in range(interface.numInterfaces()):
        ifnames.append(interface.name(i))

except Exception as inst:
    print type(inst)  # the exception instance
    print inst.args  # arguments stored in .args
    print inst  # __str__ allows args to printed directly

ntop.printHTMLHeader('Test Mininet NTOP Env', 1, 0)
ntop.sendString("Hello, " + name + "<br>")
ntop.sendString("Ntop Information: %s %s %s" % (version, os, uptime))
ntop.sendString("Here are my interfaces: <br>")
ntop.sendString(json.dumps(ifnames, sort_keys=True, indent=4))
ntop.printHTMLFooter()