Powershell IP 扫描器

标签 powershell

我有这个 powershell 脚本来检查未使用的 IP

$ipgroupes = "192.168.2"
$ipstart = 1
$ipend = 255

$ipstart..$ipend  | ForEach-Object{
    $ip = "$ipgroupes.0" -replace "0$",$_

If (-not(Resolve-DnsName -Name $ip -QuickTimeout -Type ANY -ErrorAction              
    SilentlyContinue) -And (!(Test-Connection $ip -count 1 -quiet)))

    {

        write-host "$ip is not used" -ForegroundColor Green


    }



}

脚本工作正常,但我被要求从搜索中排除 ip 80 到 149。我需要有关如何完成此操作的帮助?

最佳答案

试试这个。要撤消排除,您可以将两个排除值设置为 0

$ipgroupes = '192.168.2'
$iprange = 1..255
$excluderange = 80..149

$iprange | Where-Object {$_ -notin $excluderange} | ForEach-Object {
    "$ipgroupes.$_"
}

*编辑:在马特的帮助下更新

关于Powershell IP 扫描器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37078053/

相关文章:

powershell - 如何通过powershell删除文件夹的只读属性?

powershell - 为什么我在 Get-Module 的结果中没有列出 Microsoft.Powershell.Core?

powershell - 排除文件夹以减小图像尺寸

powershell - 替换powershell中变量的一部分而不替换其余部分?

Powershell 脚本可根据程序的版本或安装路径远程更改注册表设置

powershell - Powershell和cmd环境变量

powershell - 无法发送Powershell电子邮件-您无法在空值表达式上调用方法

PowerShell:重定向 mysqldump.exe 的错误

azure - 删除 X 天前的 Azure 快照

powershell - 用例子为初学者讲解PowerShell中的ACL对象属性 "SetAccessRuleProtection"