通过 PowerShell 脚本中的 DHCP 服务器检索客户端的 IP 地址及其 MAC 地址

Retrieve a client's IP address with its MAC address via the DHCP server in a PowerShell script

我的问题是:多亏了 PowerShell 脚本,我已经检索到了瘦客户端的 MAC 地址。该脚本在客户端计算机上执行,我想通过我的脚本联系 DHCP 服务器以恢复分配给我的瘦客户端的 IP 地址。如果您认识其他人,除了联系 DHCP 服务器之外,我对其他解决方案持开放态度,但我需要当前地址并且没有失败的可能性,我想在变量中输出 IP 以显示它。

我试过了,但我认为它只能在 DHCP 服务器上工作,但在我的情况下这是不可能的。 https://thewayeye.net/2016/10/8/find-a-mac-microsoft-dhcp/

我现在有这个:

$mac

有了这个输出:

847BEBEE****

因此,我需要来自 DHCP 服务器的 MAC 地址的瘦客户端的 IP 地址,最好是避免由于 ARP table 而导致的错误,ARP 由于非常大而并不总是有效我网络中的工作站数量(大型企业)。

我终于找到了一个简单地通过 DHCP 检索 IP 地址的解决方案:

Get-DhcpServerv4Scope -ComputerName $dhcpserver | Get-DhcpServerv4Lease -ComputerName $dhcpserver | where{$_.clientid -eq $macaddress}

mac 地址格式必须是 xx-xx-xx-xx-xx-xx(用破折号代替冒号)

但是,您必须安装 the RSAT microsoft administration tools 并且您的帐户具有查询 DHCP 服务器的必要权限。

参考,运行另一个用户下的powershell将其固定到任务栏,"SHIFT+Right Clic""Run with another user"