c# 做ping检测

猿掌柜
2021-04-09 / 0 评论 / 57 阅读 / 正在检测是否收录...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace IP
{
    class Program
    {
        private static Ping Ping;

        static void Main(string[] args)
        {
            Ping = new Ping();
            Console.WriteLine("输入IP段后回车");
            int ip = int.Parse(Console.ReadLine());
            for (int i = 1; i < 256; i++)
            {
                PingReply pingReply = Ping.Send("192.168."+ ip + "."+i+"");
                if (pingReply.Status == IPStatus.Success)
                {
                    Console.WriteLine("192.168." + ip + "." + i + "");
                }
                else
                {
                   // Console.WriteLine(i);
                }
            }
            
            Console.ReadLine();
            Console.ReadKey();
        }
    }
}
2

评论 (0)

取消