Detect ip of mac using nmap

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import commands
ip = '115.156.233.0-255'
mac = '40:8D:5C:E4:3A:E1'
results = commands.getoutput('sudo nmap -sP -n '+ip).split('\n')
for i, r in enumerate(results):
    if mac in r:
        dst = results[i-2].split(' ')[-1]
        print "Found Machine"
        with open('/home/duino/.ipaddress', 'w') as fid:
            fid.write(dst)
        print "Written to ~/.ipaddress"

你可能感兴趣的:(python,linux)