Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: bitplane/netmapui
base: f8b4b199a6
head fork: bitplane/netmapui
compare: 8cf073c873
Checking mergeability… Don't worry, you can still create the pull request.
  • 4 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 03, 2012
@bitplane Added a function which gets all available discoverers 5fab40f
@bitplane Added a function which starts the network discovery process.
Okay, now we can actually start scanning...
@bitplane bug: Arp interface name was actually mask e59a337
@bitplane Discoverer threads are now daemons.
This means they actually quit when the main thread quits, they can be
forcefully closed rather than having to politely join(). Yeah it's
sloppy, yeah it's ugly, but it takes less writing than this commit
Showing with 51 additions and 7 deletions.
  1. +50 −6
  2. +1 −1 
@@ -1,12 +1,21 @@
-"""This module defines the root discovery class, and provides a way
-to load all the available discovery modules.
+"""The root network discovery class.
+This module provides the "Discoverer" base class, a background task
+which discovers machines and the services they're running, pushing
+the output to a queue.
+It also provides functions which can load and start all the available
+import os
+from glob import glob
from time import sleep
from threading import Thread
class Discoverer(Thread):
- """The discovery class itself.
+ """The base network discovery class.
+ Instances of these run forever in the background, finding new nodes,
+ networks and services, passing them to an output queue.
@@ -34,10 +43,11 @@ def __init__(self, output, loopTime=60):
self.output = output
self.loopTime = loopTime
+ self.daemon = True
def run(self):
"""Runs this detector forever in a loop.
- Override this method if your discoverer already loops
+ You can override this method if your discoverer already loops
while True:
@@ -45,8 +55,42 @@ def run(self):
def runOnce(self):
- """The main loop of the discoverer.
- Override this method and do your thing in here.
+ """Runs one loop of your discoverer.
+ Override this method and do self.output.put(dict)
+def getAllDiscoverers():
+ """Gets all available discoverer classes.
+ Each Discoverer exists as a file named Dicoverer_*.py in this
+ script's directory. This function creates each one and returns
+ a list of their classes, which can be used to construct objects.
+ """
+ classes = []
+ basepath = os.path.dirname(os.path.realpath(__file__))
+ for name in glob('{base}/Discoverer_*.py'.format(base=basepath)):
+ modname = os.path.splitext(os.path.split(name)[1])[0]
+ module = __import__('{mod}'.format(mod=modname))
+ classes.append(getattr(module, modname))
+ return classes
+def startDiscovery(output, intrusive=False):
+ """Starts the discovery process.
+ Creates every available discoverer and points them at the output
+ queue. Returns a list of objects, which are running threads.
+ output: The queue where discovery events will be sent.
+ intrusive: If set to True, returns discoverers that poke around
+ the network in ways that might upset your network admin.
+ """
+ classes = filter(lambda d: intrusive or not d.isIntrusive,
+ getAllDiscoverers())
+ instances = [klass(output) for klass in classes]
+ for discoverer in instances:
+ discoverer.start()
+ return instances
2 
@@ -31,7 +31,7 @@ def runOnce(self):
out = {'device':
{'ipv4.address': tokens[0],
'eth.address' : tokens[3],
- '' : tokens[4]}}
+ '' : tokens[5]}}

No commit comments for this range

Something went wrong with that request. Please try again.