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))
# 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()
# # (C) 2010 -David Votino # import ntop import interface import json rsp = {} rsp['version'] = ntop.version(); rsp['os'] = ntop.os(); rsp['uptime'] = ntop.uptime(); ntop.sendHTTPHeader(1) # 1 = HTTP ntop.sendString(json.dumps(rsp, sort_keys=False, indent=4))
# # (C) 2010 - Luca Deri # import ntop import interface import json rsp = {} rsp['version'] = ntop.version() rsp['os'] = ntop.os() rsp['uptime'] = ntop.uptime() rsp['python_modules'] = os.listdir("python/json") for module in rsp['python_modules']: if ((module[0] == '.') or (module[len(module) - 1] == '~')): rsp['python_modules'].remove(module) ntop.sendHTTPHeader(12) # 12 = JSON ntop.sendString(json.dumps(rsp, sort_keys=True, indent=4))
#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))