• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# NetworkInformation.PingOptions类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: Ping

        public Ping()
        {
            this.InitializeComponent();
            this.DoUpdateForm = this.UpdateForm;

            // Create a buffer of 32 bytes of data to be transmitted.
            this.buffer = Encoding.ASCII.GetBytes(new String('.', 32));
            // Jump though 50 routing nodes tops, and don't fragment the packet
            this.packetOptions = new PingOptions(50, true);

            this.InitializeGraph();

            this.dataGridView1.SuspendLayout();

            this.dataGridView1.Columns.Add("1", "Count");
            this.dataGridView1.Columns.Add("2", "Status");
            this.dataGridView1.Columns.Add("3", "Host name");
            this.dataGridView1.Columns.Add("4", "Destination");
            this.dataGridView1.Columns.Add("5", "Bytes");
            this.dataGridView1.Columns.Add("6", "Time to live");
            this.dataGridView1.Columns.Add("7", "Roundtrip time");
            this.dataGridView1.Columns.Add("8", "Time");

            this.dataGridView1.ResumeLayout(true);
        }
开发者ID:RSchwoerer,项目名称:Terminals,代码行数:25,代码来源:Ping.cs


示例17: PingServer

        private void PingServer(string server)
        {
            string result = "Test failed!";

            var pingSender = new Ping();
            var options = new PingOptions();
            options.DontFragment = true;

            // Create a buffer of 32 bytes of data to be transmitted.
            const string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = Encoding.ASCII.GetBytes(data);
            const int timeout = 120;
            try
            {
                var reply = pingSender.Send(server, timeout, buffer, options);
                if (reply != null && reply.Status == IPStatus.Success)
                {
                    result = String.Format("Address: {0}\n", reply.Address.ToString());
                    result += String.Format("RoundTrip time: {0}\n", reply.RoundtripTime);
                    result += String.Format("Buffer size: {0}\n", reply.Buffer.Length);
                    result += Environment.NewLine;
                    result += "Test successful!\n";
                }
            }
            catch (Exception) { }

            MessageBox.Show(result, "Test Result");
        }
开发者ID:mlaitinen,项目名称:qvsvnlogconnector,代码行数:28,代码来源:Login.xaml.cs


示例18: frm_wait_Shown

 private void frm_wait_Shown(object sender, EventArgs e)
 {
     frm_main frm = (frm_main)this.Owner;
     address = frm.current_pos;
     curr_pos = address;
     //Ping POS
     Ping png = new Ping();
     PingOptions opt = new PingOptions();
     opt.DontFragment = true;
     string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
     byte[] buffer = Encoding.ASCII.GetBytes (data);
     int timeout = 800;
     PingReply reply = png.Send(address, timeout, buffer, opt);
     if (reply.Status == IPStatus.Success)
     {
         if (Directory.Exists(@"\\" + address + @"\POS\Command\"))
         {
             address = @"\\" + address + @"\POS\Command\req18";
             using (File.Create(address)) { }
         }
         else
         {
             MessageBox.Show("Нету связи с POS терминалом или папка Command не доступна", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             this.Close();
         }
     }
     else
     {
         MessageBox.Show("Нету связи с POS терминалом или папка Command не доступна", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         this.Close();
     }
     bg_worker.WorkerSupportsCancellation = true;
     bg_worker.RunWorkerAsync();
 }
开发者ID:sylion,项目名称:SMarketSettings,代码行数:34,代码来源:frm_wait.cs


示例19: TestConnection

 public static bool TestConnection(string smtpServerAddress, int port)
 {
     Ping pingSender = new Ping();
     PingOptions options = new PingOptions();
     options.DontFragment = true;
     PingReply reply = null;
     try
     {
         reply = pingSender.Send(smtpServerAddress, 12000, Encoding.ASCII.GetBytes("SHIT"), options);
     }
     catch (System.Net.NetworkInformation.PingException)
     {
         return false;
     }
     if (reply.Status == IPStatus.Success)
     {
         IPHostEntry hostEntry = Dns.GetHostEntry(smtpServerAddress);
         IPEndPoint endPoint = new IPEndPoint(hostEntry.AddressList[0], port);
         using (Socket tcpSocket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
         {
             tcpSocket.Connect(endPoint);
             if (!CheckResponse(tcpSocket, 220))
                 return false;
             SendData(tcpSocket, string.Format("HELO {0}\r\n", Dns.GetHostName()));
             if (!CheckResponse(tcpSocket, 250))
                 return false;
             return true;
         }
     }
     else
         return false;
 }
开发者ID:RenzoBit,项目名称:SIGRE,代码行数:32,代码来源:Correo.cs


示例20: TargetFound

        public string TargetFound(string target)
        {
            try
            {
                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 = 120;
                PingReply reply = pingSender.Send(target, timeout, buffer, options);
                if (reply.Status == IPStatus.Success)
                {
                    return "targetfound";
                }
                else { return "targetnotfound"; }
            }
            catch(Exception e)
            {
                string CaughtException = e.ToString();
                return CaughtException.Substring(0, CaughtException.IndexOf(Environment.NewLine));
            }
        }
开发者ID:jeremysiebers,项目名称:Siebwalde-Source,代码行数:28,代码来源:PingTarget.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Security.LazyAsyncResult类代码示例发布时间:2022-05-26
下一篇:
C# NetworkInformation.Ping类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap