当前位置: 首页>>代码示例>>C#>>正文


C# NetworkInformation.PingOptions类代码示例

本文整理汇总了C#中System.Net.NetworkInformation.PingOptions的典型用法代码示例。如果您正苦于以下问题:C# PingOptions类的具体用法?C# PingOptions怎么用?C# PingOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PingOptions类属于System.Net.NetworkInformation命名空间,在下文中一共展示了PingOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InternalSendAsync

        private async void InternalSendAsync(IPAddress address, byte[] buffer, int timeout, PingOptions options)
        {
            AsyncOperation asyncOp = _asyncOp;
            SendOrPostCallback callback = _onPingCompletedDelegate;

            PingReply pr = null;
            Exception pingException = null;

            try
            {
                if (RawSocketPermissions.CanUseRawSockets())
                {
                    pr = await SendIcmpEchoRequestOverRawSocket(address, buffer, timeout, options).ConfigureAwait(false);
                }
                else
                {
                    pr = await SendWithPingUtility(address, buffer, timeout, options).ConfigureAwait(false);
                }
            }
            catch (Exception e)
            {
                pingException = e;
            }

            // At this point, either PR has a real PingReply in it, or pingException has an Exception in it.
            var ea = new PingCompletedEventArgs(
                pr,
                pingException,
                false,
                asyncOp.UserSuppliedState);

            Finish();
            asyncOp.PostOperationCompleted(callback, ea);
        }
开发者ID:IharBury,项目名称:corefx,代码行数:34,代码来源:Ping.Unix.cs

示例2: ping

        public static string[] ping(string host)
        {
            try
            {
                Ping pingSender = new Ping();
                PingOptions options = new PingOptions();

                // Use the default Ttl value which is 128, e
                // but change the fragmentation behavior.
                options.DontFragment = true;

                // Create a buffer of 32 bytes of data to be transmitted.
                string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
                byte[] buffer = Encoding.ASCII.GetBytes(data);
                int timeout = 120;
                PingReply reply = pingSender.Send(host, timeout, buffer, options);
                string[] ping = new string[2];
                if (reply.Status == IPStatus.Success)
                {

                    ping[0] = reply.RoundtripTime.ToString();
                    ping[1] = reply.Options.Ttl.ToString();

                }
                else { ping[0] = "Error"; }

                return ping;
            }
            catch
            {
                string[] err = new string[1];
                err[0] = "Error\n Possibly you entered a malformed IP or domain.";
                return err;
            }
        }
开发者ID:xandout,项目名称:libnettools,代码行数:35,代码来源:icmp.cs

示例3: PingServer

        static void PingServer()
        {
            using (StreamReader reader = new StreamReader("guiConfig.json"))
            {
                string serverJson = reader.ReadToEnd();
                ServerModel serverModel = JsonConvert.DeserializeObject<ServerModel>(serverJson);

                if (serverModel != null && serverModel.configs != null && serverModel.configs.Count > 0)
                {
                    foreach (Server server in serverModel.configs)
                    {
                        string strIp = server.server;
                        Ping ping = new Ping();
                        PingOptions options = new PingOptions();
                        options.DontFragment = true;
                        //测试数据
                        string data = "test data abcabc";
                        byte[] buffer = Encoding.ASCII.GetBytes(data);
                        //设置超时时间
                        int timeout = 2000;
                        //调用同步 send 方法发送数据,将返回结果保存至PingReply实例
                        PingReply reply = ping.Send(strIp, timeout, buffer, options);
                        if (reply.Status == IPStatus.Success)
                        {
                            Console.WriteLine(string.Format("{0}---delay: {1}ms", server.remarks, reply.RoundtripTime));
                        }
                    }
                }
            }
        }
开发者ID:zcsscfc,项目名称:vic_demo,代码行数:30,代码来源:Program.cs

示例4: checkInternetConnection

        public static bool checkInternetConnection()
        {
            Ping myPing = new Ping();
            String host = "google.com";
            byte[] buffer = new byte[5];
            int timeout = 50;
            PingOptions pingOptions = new PingOptions();
            try
            {
                PingReply reply = myPing.Send(host, timeout, buffer, pingOptions);
                if (reply.Status == IPStatus.Success)
                {
                    return true;
                }
            }
            catch (PingException exp)
            {
                Logs.system("Intenet connection not available: " + exp.Message, Logs.TYPE_ERROR, exp);
                return false;
            }
            catch (Exception exp)
            {
                Logs.system("Internet connection not available: " + exp.Message, Logs.TYPE_ERROR, exp);
                return false;
            }

            return false;
        }
开发者ID:sonrac,项目名称:wincc_tags_parser,代码行数:28,代码来源:RequestSend.cs

示例5: launchPing

        public void launchPing(string IPAddress, string Hostname)
        {
            Ping newPing = new Ping();
            PingOptions options = new PingOptions();
            string data = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 120;
            bool shouldLoop = true;

            while (shouldLoop == true)
            {
                PingReply reply = newPing.Send(IPAddress, timeout, buffer, options);

                if (reply.Status == IPStatus.Success)
                {
                    Console.Title = Hostname;
                    Console.WriteLine("Reply from Address: {0} with a round trip time of {1}ms", IPAddress, reply.RoundtripTime.ToString());
                    System.Threading.Thread.Sleep(1000);
                }
                else
                {
                    Console.WriteLine("Destination host unreachable or is not responding.");
                    System.Threading.Thread.Sleep(1000);
                }
            }
        }
开发者ID:kaelscion,项目名称:ping-labeler,代码行数:26,代码来源:PingClass.cs

示例6: Main

 public static int Main(string[] args)
 {
     try {
         Arguments CommandLine=new Arguments(args);
         if (CommandLine["ip"]!=null) {
             string pingIP = CommandLine["ip"];
             Ping pingSender = new Ping();
             PingOptions options = new PingOptions();
             options.DontFragment=true;
             string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
             byte[] buffer = Encoding.ASCII.GetBytes(data);
             int timeout = 120;
             PingReply reply = pingSender.Send(pingIP,timeout,buffer,options);
             if (reply.Status==IPStatus.Success) {
                 WriteToConsole("RoundTrip time: "+reply.RoundtripTime);
             } else if (reply.Status==IPStatus.TimedOut) {
                 return (int) ExitCode.Timeout;
             }
         } else {
             printHelp();
         }
         return (int) ExitCode.Success;
     } catch (Exception) {
         return (int) ExitCode.Error;
     }
 }
开发者ID:nilsonmorais,项目名称:ping-app-net,代码行数:26,代码来源:Program.cs

示例7: buttonPing_Click

 private void buttonPing_Click(object sender, EventArgs e)
 {
     this.listBoxResult.Items.Clear();
     //远程服务器IP
     string ipString = this.textBoxRemoteIp.Text.ToString().Trim();
     //构造Ping实例
     Ping pingSender = new Ping();
     //Ping选项设置
     PingOptions options = new PingOptions();
     options.DontFragment = true;
     //测试数据
     string data = "test data abcabc";
     byte[] buffer = Encoding.ASCII.GetBytes(data);
     //设置超时时间
     int timeout = 120;
     //调用同步send方法发送数据,将返回结果保存至PingReply实例
     PingReply reply = pingSender.Send(ipString, timeout, buffer, options);
     if (reply.Status == IPStatus.Success)
     {
         listBoxResult.Items.Add("答复的主机地址: " + reply.Address.ToString());
         listBoxResult.Items.Add("往返时间: " + reply.RoundtripTime);
         listBoxResult.Items.Add("生存时间(TTL): " + reply.Options.Ttl);
         listBoxResult.Items.Add("是否控制数据包的分段: " + reply.Options.DontFragment);
         listBoxResult.Items.Add("缓冲区大小: " + reply.Buffer.Length);
     }
     else
     {
         listBoxResult.Items.Add(reply.Status.ToString());
     }
 }
开发者ID:muupu,项目名称:IpAddress-and-NetworkInterface,代码行数:30,代码来源:MainForm.cs

示例8: isValidDomain

        public static void isValidDomain()
        {
            try
            {
                Ping pingsender = new Ping();
                PingOptions options = new PingOptions(128, true);
                string data = "aaaaaaaaaaaaaaaaaaa";
                byte[] buffer = Encoding.ASCII.GetBytes(data);
                /*PingReply reply = pingsender.Send(Classes.variablen.domain);

                if (reply.Status == IPStatus.Success)
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Domain wurde gefunden!");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }
                else if (reply.Status == IPStatus.TimedOut)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Domain wurde nicht gefunden!");
                    Console.ForegroundColor = ConsoleColor.Gray;
                }*/
            }
            catch (Exception ex)
            {
                Classes.logger._elogger(ex);
            }
        }
开发者ID:MadsDocs,项目名称:ADUser,代码行数:28,代码来源:misc.cs

示例9: Ping

        bool Ping(string host)
        {
            Ping pingSender = new Ping();
            PingOptions options = new PingOptions();

            // Use the default Ttl value which is 128,
            // but change the fragmentation behavior.
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            int timeout = 500;
            PingReply reply = pingSender.Send(host, timeout, buffer, options);
            if (reply.Status == IPStatus.Success)
            {
                Console.WriteLine("Ping successful, getting HTTP response code");
                return true;
            }
            else
            {
                Console.WriteLine("Ping Failed, server is either down or took too long to respond.");
                return false;
            }
        }
开发者ID:Archived-Repos-Tknoguy,项目名称:Hosty,代码行数:25,代码来源:NetworkHandler.cs

示例10: isAlive

 public static bool isAlive(string IP)
 {
     try
     {
         Ping pingSender = new Ping();
         PingOptions options = new PingOptions();
         options.DontFragment = true;
         string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
         byte[] buffer = Encoding.ASCII.GetBytes(data);
         int timeout = 10;
         PingReply reply = pingSender.Send(IP, timeout, buffer, options);
         if (reply.Status == IPStatus.Success)
         {
             return (true);
         }
         else
         {
             Settings.SetLog("Failed to ping " + IP);
             return (false);
         }
     }
     catch (Exception e)
     {
         Settings.SetLog("Failed to ping " + IP);
         return (false);
     }
 }
开发者ID:dannyboy997,项目名称:Doorbell-Monitor,代码行数:27,代码来源:TCPClient.cs

示例11: CheckConnectionIpInformations

        /// <summary>
        /// Permet de tester la bonne connectivité avec une adresse IP.
        /// </summary>
        /// <param name="IP"></param>
        /// <returns></returns>
        public static Boolean CheckConnectionIpInformations(string IP)
        {
            if (!String.IsNullOrEmpty(IP))
            {
                using (Ping pingSender = new Ping())
                {
                    PingOptions options = new PingOptions();
                    options.DontFragment = true;

                    String data = new String('a', 32);
                    byte[] buffer = Encoding.ASCII.GetBytes(data);
                    int timeout = 20;
                    try
                    {
                        PingReply reply = pingSender.Send(IP, timeout, buffer, options);
                        if (reply.Status != IPStatus.Success)
                        {
                            Notifier.ShowMessage("Adresse IP du serveur MySQL (ou MariaDB) est injoignable.", "Serveur MySQL injoignable", "error", 3);
                            return false;
                        }
                    }
                    catch
                    {
                        Notifier.ShowMessage("Impossible d'établir un test sur l'adresse IP du serveur MySQL (ou MariaDB).", "Adresse IP non testable", "error", 3);
                        return false;
                    }
                    return true;
                }
            }
            else
            {
                Notifier.ShowMessage("Adresse IP serveur MySQL (ou MariaDB) incorrecte.", "Format de l'adresse IP", "error", 3);
                return false;
            }
        }
开发者ID:0ups,项目名称:dOnuts-InterfaceTablette,代码行数:40,代码来源:GestionConnection.cs

示例12: Ping

 public static async Task<PingReply> Ping(string hostNameOrIPAddress, int ttl = 0)
 {
     var pinger = new Ping();
     var options = new PingOptions(ttl, dontFragment: true);
     
     return await pinger.SendTaskAsync(hostNameOrIPAddress, 0x1388, DefaultSendBuffer, options);
 }
开发者ID:bhuvak,项目名称:NuGetOperations,代码行数:7,代码来源:NetworkHelpers.cs

示例13: PingHost

        public static PingResult PingHost(string host, int timeout = 1000, int pingCount = 4, int waitTime = 100)
        {
            PingResult pingResult = new PingResult();
            IPAddress address = GetIpFromHost(host);
            byte[] buffer = new byte[32];
            PingOptions pingOptions = new PingOptions(128, true);

            using (Ping ping = new Ping())
            {
                for (int i = 0; i < pingCount; i++)
                {
                    try
                    {
                        PingReply pingReply = ping.Send(address, timeout, buffer, pingOptions);

                        if (pingReply != null)
                        {
                            pingResult.PingReplyList.Add(pingReply);
                        }
                    }
                    catch (Exception e)
                    {
                        DebugHelper.WriteException(e);
                    }

                    if (waitTime > 0 && i + 1 < pingCount)
                    {
                        Thread.Sleep(waitTime);
                    }
                }
            }

            return pingResult;
        }
开发者ID:noscripter,项目名称:ShareX,代码行数:34,代码来源:PingHelper.cs

示例14: Ping

 public PingReply Ping(string hostOrIp)
 {
     Ping pingSender = new Ping();
     //Ping 选项设置
     PingOptions options = new PingOptions();
     options.DontFragment = true;
     //测试数据
     string data = "test data abcabc";
     byte[] buffer = Encoding.ASCII.GetBytes(data);
     //设置超时时间
     int timeout = 1200;
     //调用同步 send 方法发送数据,将返回结果保存至PingReply实例
     var reply = pingSender.Send(hostOrIp, timeout, buffer, options);
     if (reply.Status == IPStatus.Success)
     {
         return reply;
         /*lst_PingResult.Items.Add("答复的主机地址:" + reply.Address.ToString());
         lst_PingResult.Items.Add("往返时间:" + reply.RoundtripTime);
         lst_PingResult.Items.Add("生存时间(TTL):" + reply.Options.Ttl);
         lst_PingResult.Items.Add("是否控制数据包的分段:" + reply.Options.DontFragment);
         lst_PingResult.Items.Add("缓冲区大小:" + reply.Buffer.Length);  */
     }
     else
         throw new ApplicationException("Can't find the arrive at target " + hostOrIp.ToString());
 }
开发者ID:luqizheng,项目名称:Qi4Net,代码行数:25,代码来源:PingHost.cs

示例15: ReadAndPing

        public void ReadAndPing(string path)
        {
            File.OpenRead(path);
            ConsoleKeyInfo btn;

               do // Начала цикла
               {
                string ip = File.ReadLines(path);
                while (true) //читаем в ip строки из файла в path
                {
                    //Console.WriteLine(ip);
                    Ping pingSender = new Ping();
                    PingOptions options = new PingOptions();

                    options.Ttl = 60; //Продолжительность жизни пакета в секундах
                    int timeout = 120; //Таймаут выводется в ответе reply.RoundtripTime
                    string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; //Строка длиной 32 байта
                    byte[] buffer = Encoding.ASCII.GetBytes(data); //Преобразование строки в байты, выводится reply.Buffer.Length

                    PingReply reply = pingSender.Send(ip, timeout, buffer, options);

                    Console.WriteLine("Сервер: {0} Время={1} TTL={2}", reply.Address.ToString(), reply.RoundtripTime, reply.Options.Ttl); //Выводим всё на консоль

                    //ConsoleKeyInfo btn = Console.ReadKey(); //Создаём переменную которая хранит метод Описывающий нажатую клавишу консоли
                    //if (btn.Key == ConsoleKey.Escape) break;

                }

                //  ConsoleKeyInfo btn = Console.ReadKey(); //Создаём переменную которая хранит метод Описывающий нажатую клавишу консоли
                //  if (btn.Key == ConsoleKey.Escape) break;
            btn = Console.ReadKey(); //Переенная для чтения нажатия клавиши
            }
            while (btn.Key == ConsoleKey.Escape); //Чтение нажатия клавиши.
        }
开发者ID:Kubig,项目名称:Projects,代码行数:34,代码来源:ReadFile.cs


注:本文中的System.Net.NetworkInformation.PingOptions类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。