python-libnmap icon indicating copy to clipboard operation
python-libnmap copied to clipboard

event_callback does not work as documented

Open kernel-sanders opened this issue 9 years ago • 3 comments

When using an event_callback with an NmapProcess, you only receive the NmapProcess object, which does not contain any information about the host that generated the callback and is therefore pretty useless.

From the docs:

event_callback – callable function which will be ran each time nmap process outputs data. This function will receive two parameters:

  1. the nmap process object
  2. the data produced by nmap process. See readme for examples.

(there are no examples in the readme)

When attempting to implement a callback function (nm_callback in this case) there is an error because callbacks only actually take one argument. This is in line 266 of process.py: self.__nmap_event_callback(self)

Exception in thread Thread-3:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 552, in __bootstrap_inner
     self.run()
  File "/usr/local/lib/python2.7/dist-packages/libnmap/process.py", line 266, in run
     self.__nmap_event_callback(self)
 TypeError: nm_callback() takes exactly 2 arguments (1 given)

Changing nm_callback to only take 1 argument results in getting the NmapProcess object (self), which appears as: <NmapProcess(Thread-3, started 139827701815040)>

Are there any plans to include host data as a argument for the callback function? I'll see what I can do and submit a pull request if I get anywhere on it. Overall this is a great library, thanks for putting in the work to create and maintain it.

kernel-sanders avatar May 23 '15 05:05 kernel-sanders

Well I hacked together a solution that fits my use case, but won't generalize well. This returns the IPs of hosts with open ports (I am only looking for one) as the second argument to the callback function. It works well in an asynchronous threaded script. Who knows, maybe it will help someone.

My process.py file: http://pastebin.com/xjZhrpSL The patch file: http://pastebin.com/HpEbnfmD

kernel-sanders avatar May 23 '15 06:05 kernel-sanders

hey thanks for posting this. Still really really newb to async stuff. But figured this was the reason why scanning any amount of hosts resulted in run_background to just looping w/no updates.

brizzbane avatar Jun 10 '15 23:06 brizzbane

i'll check this out and adapt doc and possibly code.

savon-noir avatar Jun 21 '15 09:06 savon-noir