NetXMS Support Forum

English Support => General Support => Topic started by: gmonk63 on November 15, 2015, 08:01:08 PM

Title: IP/Mac Address lookup
Post by: gmonk63 on November 15, 2015, 08:01:08 PM
Is it possible to do IP and Mac address lookups vi nxshell or other command line tools.  I would like to be able to use a script to query where a particular mac address is connected with out having to log in using the client .  I didnt see any options listed in the nxadm  or in the nxshell api  but I could have over looked something.


Thanks
Title: Re: IP/Mac Address lookup
Post by: Alex Kirhenshtein on December 01, 2015, 10:20:44 AM
Yes, it's possible to do with nxshell. Some examples:

find by mac:
import sys
mac = sys.argv[1].upper()

for node in [o for o in s.getAllObjects() if isinstance(o, objects.Node)]:
    interfaces = node.getAllChilds(objects.GenericObject.OBJECT_INTERFACE)
    for interface in interfaces:
        if mac in interface.getMacAddress().toString().upper():
            print "%s(%d) - %s - %s" % (node.getObjectName(),
                                        node.getObjectId(),
                                        interface.getMacAddress(),
                                        interface.getIpAddressListAsString())


find by ip:
import sys
ip = sys.argv[1]

for node in [o for o in s.getAllObjects() if isinstance(o, objects.Node)]:
    interfaces = node.getAllChilds(objects.GenericObject.OBJECT_INTERFACE)
    for interface in interfaces:
        for interface_ip in interface.getIpAddressList():
            if ip in interface_ip.toString():
                print "%s(%d) - %s - %s" % (node.getObjectName(),
                                            node.getObjectId(),
                                            interface.getMacAddress(),
                                            interface.getIpAddressListAsString())


Sample session:
~/Development/netxms/src/java/nxshell/target (develop|...)% java -Dnetxms.server=127.0.0.1 -Dnetxms.login=admin -Dnetxms.password=netxms -jar nxshell-2.0-RC2.jar find_by_mac.py B2:00:1C:15:BC:E0
AirAlk.local(100) - B2:00:1C:15:BC:E0 - 0.0.0.0/0
~/Development/netxms/src/java/nxshell/target (develop|...)% java -Dnetxms.server=127.0.0.1 -Dnetxms.login=admin -Dnetxms.password=netxms -jar nxshell-2.0-RC2.jar find_by_ip.py 127
AirAlk.local(100) - 00:00:00:00:00:00 - 127.0.0.1/8
Title: Re: IP/Mac Address lookup
Post by: gmonk63 on December 01, 2015, 08:28:36 PM
oh wow you saved me so much time ... Thank you so much 
Title: Re: IP/Mac Address lookup
Post by: gmonk63 on December 03, 2015, 12:47:16 AM
Alex,

what you provided is great ... However how would I tweak this tool to provide the same functionality as  Find Mac address tool in the managment console  which also provides the switch and port the mac is connected to..
Title: Re: IP/Mac Address lookup
Post by: Alex Kirhenshtein on December 03, 2015, 09:48:02 AM
Try attached script.
Title: Re: IP/Mac Address lookup
Post by: gmonk63 on December 03, 2015, 08:42:03 PM
Works like a charm ... Thanks