码迷,mamicode.com
首页 > Windows程序 > 详细

C# 控制台程序实现 检查iP ,Ping 是否正常

时间:2015-11-04 17:46:57      阅读:406      评论:0      收藏:0      [点我收藏+]

标签:

using System;
using System.Net;
using System.Net.NetworkInformation;
class Program
{
    static void Main(string[] args)
    {
        int count = 4;
        IPAddress addr = IPAddress.Parse("220.181.111.86");
        Ping ping = new Ping();
        long timeSum = 0;
        int succCount = 0;
        //发送
        Console.WriteLine技术分享("正在ping {0}", addr);
        for (int i = 0; i < count; ++i)
        {
            PingReply pr = ping.Send(addr);
            if (pr.Status == IPStatus.TimedOut)
                Console.WriteLine("超时");
            else if (pr.Status == IPStatus.Success)
            {
                Console.WriteLine("延时:{0}毫秒", pr.RoundtripTime);
                ++succCount;
                timeSum += pr.RoundtripTime;
            }
        }
        if (timeSum != 0)
            Console.WriteLine("平均延时{0}毫秒,丢包率{1}%", 1.0 * timeSum / succCount, (count - succCount) * 100.0 / count);
        else
            Console.WriteLine("丢包率100%");
        return;
    }
}

C# 控制台程序实现 检查iP ,Ping 是否正常

标签:

原文地址:http://www.cnblogs.com/harlen/p/4936347.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!