Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Problem with -match

$
0
0

Hello Everyone!

I'm trying to create a script which picks up MAC from the output of arp -a <ipaddress> command. I have stupid error with 1 single ip where the match seems to fail:

$ip="10.52.9.19"
$mac = arp -a $ip;
arp -a $ip
($mac | ? { $_ -match $ip }) -match "([0-9A-F]{2}([:-][0-9A-F]{2}){5})"
($mac | ? { $_ -match $ip }) -match "([0-9A-F][0-9A-F]-){5}([0-9A-F][0-9A-F])"
$matches[0];

$ip="10.52.9.9"
$mac = arp -a $ip;
arp -a $ip
($mac | ? { $_ -match $ip }) -match "([0-9A-F]{2}([:-][0-9A-F]{2}){5})"
($mac | ? { $_ -match $ip }) -match "([0-9A-F][0-9A-F]-){5}([0-9A-F][0-9A-F])"
$matches[0];

For the ip 10.52.9.19 for some yet unknown reason I get back the ip instead of the MAC. This is the output of the script above:

Interface: 10.52.9.195 --- 0xa
  Internet Address      Physical Address      Type
  10.52.9.19            5c-f3-fc-e5-9e-d8     dynamic
  10.52.9.19            5c-f3-fc-e5-9e-d8     dynamic
  10.52.9.19            5c-f3-fc-e5-9e-d8     dynamic
10.52.9.19

Interface: 10.52.9.195 --- 0xa
  Internet Address      Physical Address      Type
  10.52.9.9             00-50-56-a1-00-21     dynamic
True
True
00-50-56-a1-00-21

What am I doing wrong ?



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>