1 # coding:utf-8 2 import os 3 4 cmd = {'arp': 'arp -a | find "', 5 'route': 'route PRINT ' 6 } 7 8 9 def win_mac_get(): 10 import socket 11 import re 12 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 13 s.connect(("8.8.8.8", 80)) 14 ip = (s.getsockname()[0]) 15 s.close() 16 print ip 17 __arp_cmd = cmd['arp'] + str(ip) + '"' 18 19 __inter_fices = os.popen(__arp_cmd).read().strip(' ') 20 21 id = __inter_fices.split('---')[1].split(' ')[1] 22 23 __route_cmd = cmd['route'] + id 24 routes = os.popen(__route_cmd).read().strip(' ') 25 data_list = re.findall(' (.d)...(.*)', routes) 26 dict_a = {} 27 for i in data_list: 28 dict_a[i[0]] = i[1].split('......')[0].replace(' ', '') 29 int_id = str(int(id, 16)) 30 print(dict_a[int_id]) 31 32 33 if __name__ == '__main__': 34 win_mac_get()