python - Calling get_host_byid from libnmap returns "None" instead of a host object -


using python libnmap module, have python code:

def diffscan(old, new):         added = old.diff(new).added()         in added:             anip = i.split('::')[1]             print "ip lookup " + anip + " of " + str(type(anip))             anewhost = new.get_host_byid(anip)             pprint.pprint(anewhost) 

when call function, output:

 ip lookup x.x.x.x of <type 'str'>  none  ip lookup y.y.y.y of <type 'str'>  none 

my expectation instead of "none", :

ip lookup z.z.z.z of <type 'str'> nmaphost: [z.z.z.z () - up] 

i unsure why call .get_host_byid() returning none , not nmaphost object. perhaps there wrong anip string, cannot find error.

tl;dr: called diff function incorrectly.

longer answer

there nothing wrong libnmap diff function. original code in question above has logic error , calling diff function incorrectly. returning "none" set of hosts queried did not contain requested host, expected behaviour. correct call should be:

added = new.diff(old).added() 

in other words, swapping positions of 2 variables in function call. call to

new.get_host_byid(anip) 

will work correctly. extending other diff functions, code removed hosts should be:

removed = new.diff(old).removed()  

and use

old.get_host_byid(anip) 

the code changed hosts should be

changed = new.diff(old).changed()  

and use

new.get_host_byid(anip) 

the code unchanged hosts should be

unchanged = new.diff(old).unchanged()  

and use

new.get_host_byid(anip) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -