IP/Mac Address lookup

Started by gmonk63, November 15, 2015, 08:01:08 PM

Previous topic - Next topic

gmonk63

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

Alex Kirhenshtein

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

gmonk63

oh wow you saved me so much time ... Thank you so much 

gmonk63

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..

Alex Kirhenshtein

Try attached script.

gmonk63