【问题标题】:Getting MAC from IP returns IP outside of subnet从 IP 获取 MAC 会返回子网之外的 IP
【发布时间】: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


    【解决方案1】:

    已修复。傻我。我传错了。

    $device = "192.168.2.231";
    Get-MacAddress($device);
    

    【讨论】:

      猜你喜欢
      • 2018-11-24
      • 2020-04-06
      • 2021-12-15
      • 2017-05-06
      • 2014-09-22
      • 1970-01-01
      • 1970-01-01
      • 2011-05-29
      • 1970-01-01
      相关资源
      最近更新 更多