66
66
if _AIX :
67
67
_MAC_DELIM = b'.'
68
68
_MAC_OMITS_LEADING_ZEROES = True
69
+ if sys .platform in ('darwin' , ):
70
+ _MAC_OMITS_LEADING_ZEROES = True
69
71
70
72
RESERVED_NCS , RFC_4122 , RESERVED_MICROSOFT , RESERVED_FUTURE = [
71
73
'reserved for NCS compatibility' , 'specified in RFC 4122' ,
@@ -427,7 +429,7 @@ def _find_mac_near_keyword(command, args, keywords, get_word_index):
427
429
if words [i ] in keywords :
428
430
try :
429
431
word = words [get_word_index (i )]
430
- mac = int (word . replace ( _MAC_DELIM , b'' ), 16 )
432
+ mac = _parse_mac (word )
431
433
except (ValueError , IndexError ):
432
434
# Virtual interfaces, such as those provided by
433
435
# VPNs, do not have a colon-delimited MAC address
@@ -436,7 +438,7 @@ def _find_mac_near_keyword(command, args, keywords, get_word_index):
436
438
# real MAC address
437
439
pass
438
440
else :
439
- if _is_universal (mac ):
441
+ if mac and _is_universal (mac ):
440
442
return mac
441
443
first_local_mac = first_local_mac or mac
442
444
return first_local_mac or None
@@ -453,10 +455,12 @@ def _parse_mac(word):
453
455
if len (parts ) != 6 :
454
456
return
455
457
if _MAC_OMITS_LEADING_ZEROES :
456
- # (Only) on AIX the macaddr value given is not prefixed by 0, e.g.
458
+ # on AIX and darwin the macaddr value given is not prefixed by 0, e.g. on AIX
457
459
# en0 1500 link#2 fa.bc.de.f7.62.4 110854824 0 160133733 0 0
458
460
# not
459
461
# en0 1500 link#2 fa.bc.de.f7.62.04 110854824 0 160133733 0 0
462
+ # and on darwin
463
+ # ? (224.0.0.251) at 1:0:5e:0:0:fb on en0 ifscope permanent [ethernet]
460
464
if not all (1 <= len (part ) <= 2 for part in parts ):
461
465
return
462
466
hexstr = b'' .join (part .rjust (2 , b'0' ) for part in parts )
0 commit comments