zoukankan      html  css  js  c++  java
  • PowerShell实战1:Ping_Test

    功能:批量测试远程主机的Ping值,以及根据TTL值来判断是否为Windows主机。

    使用:在C:\IP.txt中加入需要测试的主机IP或域名,一行一个。例如:

    www.google.com
    www.baidu.com
    www.cha123.com
    www.yahoo.com
    www.msn.com

    源码

      function Ping_Test {
        PROCESS {
          $ping = $false
          $results = Get-WmiObject -query `
          "SELECT * FROM Win32_PingStatus WHERE Address = '$_'"
          $RT = $results.ResponseTime
          $TTL = $results.ResponseTimeToLive
          foreach ($result in $results) {
            if ($results.StatusCode -eq 0) {
                if ($TTL -ge 98 -and $TTL -le 128)
                    {Write-Host "`n$_ Response Time=$RT ms, TTL=$TTL,It is a Windows host." -ForegroundColor Green }
                  else
                      {Write-Host "`n$_ Response Time=$RT ms, TTL=$TTL, It is NOT a Windows host." -ForegroundColor Blue}
              }
            else {
              Write-Host "`n$_ Ping failed!" -ForegroundColor Red
            }
            }
        }
      }
    cls
    Get-Content c:\IP.txt | Ping_Test

    结果:

    image
  • 相关阅读:
    EasyUI--Alert()
    asp.net 页面之间传值的几种方式
    c# 的类成员
    c# protected public private internal
    C#中的多态性
    c# 静态成员和实例成员的区别
    js确认框confirm()用法实例详解
    JS中的switch case
    分分钟用上C#中的委托和事件
    Asp.net MVC中关于@Html标签Label、Editor使用
  • 原文地址:https://www.cnblogs.com/studio313/p/1622073.html
Copyright © 2011-2022 走看看