AutoPatrol, Bureaucrats, Administrators
683
edits
m (→Usage: version autochange) |
|||
Line 190: | Line 190: | ||
for node in matched: | for node in matched: | ||
print node.getObjectId(), node.getObjectName(), node.getPrimaryIP().getHostAddress() | print node.getObjectId(), node.getObjectName(), node.getPrimaryIP().getHostAddress() | ||
</syntaxhighlight> | |||
== Find MAC address == | |||
MAC address to find passed as parameter. | |||
<syntaxhighlight lang="python"> | |||
import sys | |||
mac = MacAddress.parseMacAddress(sys.argv[1].upper()) | |||
if not mac: | |||
print 'Cannot parse MAC address' | |||
else: | |||
print 'Parsed MAC:', mac | |||
cp = s.findConnectionPoint(mac) | |||
if not cp: | |||
'No connection found' | |||
else: | |||
host = s.findObjectById(cp.getLocalNodeId()) | |||
bridge = session.findObjectById(cp.getNodeId()) | |||
iface = s.findObjectById(cp.getInterfaceId()) | |||
if bridge and iface: | |||
if cp.getType() == ConnectionPointType.WIRELESS: | |||
if host: | |||
print "Node %s is connected to wireless access point %s/%s" % (host.getObjectName(), bridge.getObjectName(), iface.getObjectName()) | |||
else: | |||
if cp.getLocalIpAddress(): | |||
print "Node with IP address %s and MAC address %s is connected to wireless access point %s/%s" % (cp.getLocalIpAddress().getHostAddress(), cp.getLocalMacAddress(), bridge.getObjectName(), iface.getObjectName()) | |||
else: | |||
print "Node with MAC address %s is connected to wireless access point %s/%s" % (cp.getLocalMacAddress(), bridge.getObjectName(), iface.getObjectName()) | |||
else: | |||
if host: | |||
print "Node %s is %s connected to network switch %s port %s" % (host.getObjectName(), "directly" if cp.getType() == ConnectionPointType.DIRECT else "indirectly", bridge.getObjectName(), iface.getObjectName()) | |||
else: | |||
if cp.getLocalIpAddress(): | |||
print "Node with IP address %s and MAC address %s is %s connected to network switch %s port %s" % (cp.getLocalIpAddress().getHostAddress(), cp.getLocalMacAddress(), "directly" if cp.getType() == ConnectionPointType.DIRECT else "indirectly", bridge.getObjectName(), iface.getObjectName()) | |||
else: | |||
print "Node with MAC address %s is %s connected to network switch %s port %s" % (cp.getLocalMacAddress(), "directly" if cp.getType() == ConnectionPointType.DIRECT else "indirectly", bridge.getObjectName(), iface.getObjectName()) | |||
else: | |||
print 'No connection found' | |||
</syntaxhighlight> | </syntaxhighlight> |