【发布时间】:2016-09-24 15:30:37
【问题描述】:
function Get-MacAddress {
param( [string]$device= $( throw "Please specify device" ) )
if ( $device | ? { $_ -match "[0-9].[0-9].[0-9].[0-9]" } )
{
#"Searching by IP Address"
$ip = $device
} else {
#"Searching by Host Name"
$ip = [System.Net.Dns]::GetHostByName($device).AddressList[0].IpAddressToString
}
arp -d; # purge arp cache
$ping = ( new-object System.Net.NetworkInformation.Ping ).Send($ip);
$mac = arp -a;
if($ping)
{
( $mac | ? { $_ -match $ip } ) -match "([0-9A-F]{2}([:-][0-9A-F]{2}){5})" | out-null;
if ( $matches ) {
$matches[0];
} else {
"Not Found"
}
}
}
Get-MacAddress(192.168.2.231);
如果我运行它,我会得到以下信息:
192.168.56.1
我不确定我是如何获得该 IP 而不是 MAC。
我需要做的是获取 IP 地址的 MAC,这样当我可以扫描 IP 时,我可以提取具有特定 MAC 的特定 IP。
这些不是 Windows 机器,而是网络上的其他随机设备。
【问题讨论】:
标签: powershell ip mac-address scanning