Powershell-批量清理DHCP BAD_ADDRESS地址

1.Powershell查詢DHCP BAD_Address列表

需求:

DHCP服務器地址池頻繁被Bad_Address垃圾請求打滿;

安全及網絡同事在溯源排錯過程中,需要及時清理垃圾地址信息,防止新用戶無法正常獲取IP地址信息;

640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1


查詢當前作用域信息:

Get-DhcpServerv4Lease -ComputerName 10.78.0.226 -ScopeId 10.78.48.0

640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1

查詢當前地址池主機名爲BAD_Address:

Get-DhcpServerv4Lease -ComputerName 10.78.0.226 -ScopeId 10.78.48.0 |where {$_.Hostname -like "BAD*" }
Get-DhcpServerv4Lease語法:
Get-DhcpServerv4Lease [-ScopeId] <ipaddress> [<CommonParameters>]
Get-DhcpServerv4Lease  [<CommonParameters>]
Get-DhcpServerv4Lease [-ScopeId] <ipaddress> [-ClientId] <string[]> [<CommonParameters>]
Get-DhcpServerv4Lease [[-ScopeId] <ipaddress>] [<CommonParameters>]
描述:
獲取從動態主機配置協議(DHCP)服務器服務的一個或多個租賃記錄。
如果指定ScopeId參數,則返回指定範圍內的活動租約。要獲得包括Active,Offered,Declined和Expired在內的各種租約,必須指定AllLeases參數。
如果指定IPAddress參數,則返回指定IP地址的租約記錄。
如果指定ClientId和ScopeId參數,則返回指定範圍內指定ClientId參數值的租約。
如果指定BadLeases和ScopeId參數,則返回指定範圍的所有錯誤租約記錄。
如果指定不帶ScopeId參數的BadLeases參數,則返回DHCP服務器服務中的所有錯誤租約記錄。

2.批量清理無效Bad_Address地址池

批量過濾並清理無效BAD_Address地址釋放地址空間:

$Computername = "10.78.0.226"
$Scopeid = "10.78.48.0"
Import-Module DHCPServer
foreach ($Object in Get-DhcpServerv4Lease -ComputerName $Computername -ScopeId $Scopeid )
{
if ($object.HostName –like 'BAD_A*')
{
Remove-DhcpServerv4Lease -ComputerName $Computername -ScopeId $Scopeid -ClientId $object.ClientId
}
}

640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1

語法:
Remove-DhcpServerv4Lease [<CommonParameters>]
Remove-DhcpServerv4Lease [-ScopeId] <ipaddress> [<CommonParameters>]
Remove-DhcpServerv4Lease [-ScopeId] <ipaddress> [-ClientId] <string[]> [<CommonParameters>]
Remove-DhcpServerv4Lease [[-ScopeId] <ipaddress>] [<CommonParameters>]
描述:
刪除從動態主機配置協議(DHCP)服務器服務的一個或多個IPv4租約記錄。
如果指定了ScopeId參數,則刪除指定範圍的所有租約。
如果指定了IPAddress參數,則刪除由一個或多個指定IP地址標識的客戶端的租約。如果指定了ClientId和ScopeId參數,則會刪除指定範圍內指定客戶端標識符(ID)的租約。
如果指定了BadLeases和ScopeId參數,則此cmdlet將刪除指定範圍的所有錯誤租約記錄。
如果在沒有ScopeId參數的情況下指定了BadLeases參數,則此cmdlet將從DHCP服務器服務上的所有作用域中刪除所有錯誤租約。


640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章