~ubuntu-branches/ubuntu/trusty/maas/trusty-security

« back to all changes in this revision

Viewing changes to src/provisioningserver/utils/__init__.py

  • Committer: Package Import Robot
  • Author(s): Greg Lutostanski
  • Date: 2014-08-29 13:27:34 UTC
  • mto: (61.1.4 trusty-proposed)
  • mto: This revision was merged to the branch mainline in revision 62.
  • Revision ID: package-import@ubuntu.com-20140829132734-d47evihju2etdwcy
Tags: upstream-1.5.4+bzr2294
ImportĀ upstreamĀ versionĀ 1.5.4+bzr2294

Show diffs side-by-side

added added

removed removed

Lines of Context:
829
829
        if len(columns) == 5 and columns[2] == mac:
830
830
            return columns[0]
831
831
    return None
 
832
 
 
833
 
 
834
def find_mac_via_arp(ip):
 
835
    """Find the MAC address for `ip` by reading the output of arp -n.
 
836
 
 
837
    Returns `None` if the IP is not found.
 
838
 
 
839
    We do this because we aren't necessarily the only DHCP server on the
 
840
    network, so we can't check our own leases file and be guaranteed to find an
 
841
    IP that matches.
 
842
 
 
843
    :param ip: The ip address, e.g. '192.168.1.1'.
 
844
    """
 
845
 
 
846
    output = call_capture_and_check(['arp', '-n']).split('\n')
 
847
 
 
848
    for line in sorted(output):
 
849
        columns = line.split()
 
850
        if len(columns) == 5 and columns[0] == ip:
 
851
            return columns[2]
 
852
    return None