需求:
安全同事新需求,想通過IP地址及時溯源出MAC或主機名信息;
環境:
Windows Server 2016 + DHCP
分析:
記得之前寫過一篇"Powershell-過濾MAC地址對應IP地址信息"文章;
通過相同原理可實現MAC與主機名信息過濾;
步驟:
1.相關DHCP服務器命令選擇:
Get-DhcpServerv4Lease :
從動態主機配置協議(DHCP)服務器服務獲取一個或多個租約記錄。
GET-DhcpServerv4Scope :
返回指定範圍的IPv4範圍配置。如果未指定ScopeId參數,則返回動態主機配置協議(DHCP)服務器服務上配置的所有範圍。
Get-DhcpServerv4Lease[-ComputerName <String>]-IPAddress <IPAddress[]>[-CimSession <CimSession[]>][-ThrottleLimit <Int32>][-AsJob][<CommonParameters>]Get-DhcpServerv4Lease[-ComputerName <String>][-ScopeId] <IPAddress>[-ClientId] <String[]>[-CimSession <CimSession[]>][-ThrottleLimit <Int32>][-AsJob][<CommonParameters>]Get-DhcpServerv4Lease[-ComputerName <String>][-BadLeases][[-ScopeId] <IPAddress>][-CimSession <CimSession[]>][-ThrottleLimit <Int32>][-AsJob][<CommonParameters>]
2.查詢所有作用域下的租約信息,並過濾IP地址對應MAC及主機名信息:
Get-DhcpServerv4Scope |Get-DhcpServerv4Lease |where {$_.IPAddress -like "10.18.133.27"}