zoukankan      html  css  js  c++  java
  • 检测网络连通性并记录时间戳

    #Test-Connection, 之所以不采用这种方法, 是因为该命令对于丢包返回系统报错, 无法被抓取.
    $end = [datetime]"2015年4月27日 20:32:20"
    $start = Get-Date
    $count = [math]::Round(($end - $start).TotalSeconds)
    while($count -gt 0) {
    Test-Connection 208.67.222.222 -Count 100 | select -Property address, responsetime, @{n="timestamp";e={Get-Date}}, @{n="status";e={if($_.responsetime -eq $null) {"unreachable"}}} #| Export-Csv -Path "C:UsersDesktop
    esult.csv"
    $count--
    }
    

    Test-Connection : Testing connection to computer '208.67.222.222' failed: Error due to lack of resources At line:1 char:1 + Test-Connection 208.67.222.222 -Count 100 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (208.67.222.222:String) [Test-Connection], PingException + FullyQualifiedErrorId : TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand
    #win32_PingStatus, 这种方式相较上一种而言更友好, 对于丢包不会报错, 仅仅是不显示Time(ms).
    $end = [datetime]"2015年4月27日 20:32:20"
    $start = Get-Date
    $count = [math]::Round(($end - $start).TotalSeconds)
    While ($Count -gt 0) {
    Get-WmiObject -Class win32_PingStatus -Filter "address='208.67.22.220'" | select address, responsetime, @{n="timestamp";e={Get-Date}}, @{n="status";e={if($_.responsetime -eq $null ) {"unreachable"}}} | Export-Csv -Path "C:Users814072Desktop
    esult.csv" -Append
    $count--
    }
    
    Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms)
    ------        -----------     -----------      -----------                              -----    --------
    CNHZPD-4GF... 208.67.22.220                                                             32                

    参考: http://community.spiceworks.com/topic/337701-ping-via-powershell-log-results-with-timestamp

  • 相关阅读:
    在linux CentOS7 安装Nginx 部署vue
    VS Code 用Vue Cli创建项目
    CentOS8通过命令设置IP地址
    C# .net Core WebApi 系列(一)创建与使用
    JS、C#编码解码
    C#通用类库--数字转为人民币汉字大写表示
    CheckUtil类
    Windows服务用bat命令安装与卸载
    突然的兴趣,我想写一个提取图片中特定颜色图像的程序
    一些常用的基础操作记录
  • 原文地址:https://www.cnblogs.com/IvanChen/p/4493674.html
Copyright © 2011-2022 走看看