public bool Ping(string ip)
 {
     System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping();
     System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
     options.DontFragment = true;
     string data = "Test Data!";
     byte[] buffer = Encoding.ASCII.GetBytes(data);
     int timeout = 1000; // Timeout 时间,单位:毫秒
     System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, options);
     if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
       return true;
     else
       return false;
 }
        private string PingInfo(string p)
        {
            System.Net.NetworkInformation.Ping        pingSender = new System.Net.NetworkInformation.Ping();
            System.Net.NetworkInformation.PingOptions options    = new System.Net.NetworkInformation.PingOptions();

            options.DontFragment = true;

            string data = new string('a', 32);

            byte[] buffer  = System.Text.Encoding.ASCII.GetBytes(data);
            int    timeout = 120;

            System.Net.NetworkInformation.PingReply reply = pingSender.Send(p, timeout, buffer, options);

            if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
            {
                return(string.Format("\t-> Round Trip time: {1} ms, Time to live: {2}, Buffer size: {4}; ", reply.Address.ToString(), reply.RoundtripTime, reply.Options.Ttl, reply.Options.DontFragment, reply.Buffer.Length));
            }
            return("");
        }
Beispiel #3
0
        private bool Ping()
        {
            System.Net.NetworkInformation.Ping        p  = new System.Net.NetworkInformation.Ping();
            System.Net.NetworkInformation.PingOptions op = new System.Net.NetworkInformation.PingOptions();
            op.DontFragment = true;
            string data = "Test";

            byte[] buf     = Encoding.ASCII.GetBytes(data);
            int    timeout = 1000;

            System.Net.NetworkInformation.PingReply rp = p.Send("10.78.*.*", timeout, buf, op);
            if (rp.Status == System.Net.NetworkInformation.IPStatus.Success)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #4
0
        /// <summary>
        /// 是否能 Ping 通指定的主机
        /// </summary>
        /// <param name="ip">ip 地址或主机名或域名</param>
        /// <returns>true 通,false 不通</returns>
        public bool Ping(string ip)
        {
            System.Net.NetworkInformation.Ping        p       = new System.Net.NetworkInformation.Ping();
            System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
            options.DontFragment = true;
            string data = "Test Data!";

            byte[] buffer  = Encoding.ASCII.GetBytes(data);
            int    timeout = 1000; // Timeout 时间,单位:毫秒

            System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, options);
            if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #5
0
 public static long Ping(string ip)
 {
     try
     {
         System.Net.NetworkInformation.Ping        p       = new System.Net.NetworkInformation.Ping();
         System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
         options.DontFragment = true;
         string data    = "Test Data!";
         byte[] buffer  = Encoding.ASCII.GetBytes(data);
         int    timeout = 70; // Timeout 时间,单位:毫秒
         System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, options);
         if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
         {
             return(reply.RoundtripTime);
         }
     }
     catch
     {
     }
     return(999999);
 }
Beispiel #6
0
        public static bool Ping(string ip_address, int trytimes = 1)
        {
            var p       = new System.Net.NetworkInformation.Ping();
            var options = new System.Net.NetworkInformation.PingOptions {
                DontFragment = true
            };
            const string data    = "ping!";
            var          buffer  = Encoding.ASCII.GetBytes(data);
            const int    timeout = 1000; // Timeout 时间,单位:毫秒

            while (trytimes >= 0)
            {
                trytimes--;
                var reply = p.Send(ip_address, timeout, buffer, options);
                if (reply != null && reply.Status == System.Net.NetworkInformation.IPStatus.Success)
                {
                    return(true);
                }
            }
            return(false);
        }
Beispiel #7
0
            public override ConsoleOutput Logic()
            {
                base.Logic();
                System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping();

                // Wait 10 seconds for a reply.
                int timeout = 1000;

                byte[] buffer = System.Text.Encoding.ASCII.GetBytes(targetLevel);
                System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions(64, true);
                System.Net.NetworkInformation.PingReply   reply   = null;
                try
                {
                    reply = pingSender.Send(targetLevel, timeout, buffer, options);
                }
                catch (Exception ex)
                {
                    return(new ConsoleOutput("Transmit faild. " + ex.Message, ConsoleOutput.OutputType.Error));
                }

                return(new ConsoleOutput("Reply from " + reply.Address + ": bytes=" + reply.Buffer.Length + " time=" + reply.RoundtripTime + "ms Status=" + reply.Status, ConsoleOutput.OutputType.Network));
            }
Beispiel #8
0
 /// <summary>
 /// 是否能 Ping 通指定的主机
 /// </summary>
 /// <param name="ip">ip 地址或主机名或域名</param>
 /// <returns>true 通,false 不通</returns>
 private bool checkFileServerConnect(string ip)
 {
     try
     {
         System.Net.NetworkInformation.Ping        p       = new System.Net.NetworkInformation.Ping();
         System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
         options.DontFragment = true;
         string data    = "Test Data!";
         byte[] buffer  = Encoding.ASCII.GetBytes(data);
         int    timeout = 3000; // Timeout 时间,单位:毫秒
         System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, options);
         if (reply == null || reply.Status == System.Net.NetworkInformation.IPStatus.Success)
         {
             return(true);
         }
         return(false);
     }
     catch (System.Net.NetworkInformation.PingException e)
     {
         throw new Exception("找不到服务器");
     }
 }
Beispiel #9
0
 /// <summary>
 /// check the net
 /// </summary>
 /// <param name="ip"></param>
 /// <returns></returns>
 private bool Ping(string ip)
 {
     try
     {
         System.Net.NetworkInformation.Ping        p       = new System.Net.NetworkInformation.Ping();
         System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
         int timeout = 1000; // Timeout 时间,单位:毫秒
         System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout);
         if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
Beispiel #10
0
        public static bool CheckHostAvailablity(string url)
        {
            Uri uri = new Uri(url);


            System.Net.NetworkInformation.Ping        pingSender = new System.Net.NetworkInformation.Ping();
            System.Net.NetworkInformation.PingOptions options    = new System.Net.NetworkInformation.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  = System.Text.Encoding.ASCII.GetBytes(data);
            int    timeout = 120;

            System.Net.NetworkInformation.PingReply reply;
            try
            {
                reply = pingSender.Send(uri.Host, timeout, buffer, options);
                if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (System.Net.NetworkInformation.PingException)
            {
                return(false);
            }
        }
Beispiel #11
0
        public static bool IsDriveReady(string serverName)
        {
            //https://stackoverflow.com/questions/1232953/speed-up-file-exists-for-non-existing-network-shares
            // ***  SET YOUR TIMEOUT HERE  ***
            int timeout = 5;    // 5 seconds

            try
            {
                System.Net.NetworkInformation.Ping        pingSender = new System.Net.NetworkInformation.Ping();
                System.Net.NetworkInformation.PingOptions options    = new System.Net.NetworkInformation.PingOptions();
                options.DontFragment = true;
                // Enter a valid ip address
                string ipAddressOrHostName = serverName;
                string data   = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
                byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data);
                System.Net.NetworkInformation.PingReply reply = pingSender.Send(ipAddressOrHostName, timeout, buffer, options);
                return(reply.Status == System.Net.NetworkInformation.IPStatus.Success);
            }
            catch (Exception)
            {
            }

            return(false);
        }
Beispiel #12
0
        public static bool CheckConnection()
        {
            System.Net.NetworkInformation.Ping        pingSender  = new System.Net.NetworkInformation.Ping();
            System.Net.NetworkInformation.PingOptions pingOptions = new System.Net.NetworkInformation.PingOptions();

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


            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

            byte[] buffer  = System.Text.Encoding.ASCII.GetBytes(data);
            int    timeout = 120;

            try
            {
                System.Net.NetworkInformation.PingReply reply = pingSender.Send(Settings.NETWORK_PING_HOST, timeout, buffer, pingOptions);
                if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
                {
                    PropertyService.Set("Unity.Connection", true);
                    return(true);
                }
                else
                {
                    PropertyService.Set("Unity.Connection", false);
                    return(false);
                }
            }
            catch
            {
                PropertyService.Set("Unity.Connection", true);
                return(false);
            }
        }
Beispiel #13
0
 public System.Net.NetworkInformation.PingReply Send(string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options)
 {
     return(default(System.Net.NetworkInformation.PingReply));
 }
Beispiel #14
0
 private static bool IsDriveReady(string serverName)
 {
     // ***  SET YOUR TIMEOUT HERE  ***
     int timeout = 5;    // 5 seconds
     System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping();
     System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
     options.DontFragment = true;
     // Enter a valid ip address
     string ipAddressOrHostName = serverName;
     string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
     byte[] buffer = System.Text.Encoding.ASCII.GetBytes(data);
     System.Net.NetworkInformation.PingReply reply = pingSender.Send(ipAddressOrHostName, timeout, buffer, options);
     return (reply.Status == System.Net.NetworkInformation.IPStatus.Success);
 }
Beispiel #15
0
 public PingReply Send(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options)
 {
     return(default(System.Net.NetworkInformation.PingReply));
 }
Beispiel #16
0
 public void SendAsync(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options, object userToken)
 {
 }
Beispiel #17
0
 public PingReply Send(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options)
 {
     throw null;
 }
Beispiel #18
0
 public System.Threading.Tasks.Task <System.Net.NetworkInformation.PingReply> SendPingAsync(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options)
 {
     return(default(System.Threading.Tasks.Task <System.Net.NetworkInformation.PingReply>));
 }
		public static bool CheckConnection()
		{
			System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping();
			System.Net.NetworkInformation.PingOptions pingOptions = new System.Net.NetworkInformation.PingOptions();
			
			// Use the default Ttl value which is 128,
            // but change the fragmentation behavior.
            pingOptions.DontFragment = true;

			
            // Create a buffer of 32 bytes of data to be transmitted.
            string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
            byte[] buffer = System.Text.Encoding.ASCII.GetBytes (data);
            int timeout = 120;
			 
			try
			{
				System.Net.NetworkInformation.PingReply reply = pingSender.Send (Settings.NETWORK_PING_HOST, timeout, buffer, pingOptions);
				if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
	            {
					PropertyService.Set("Unity.Connection", true);
					return true;
				}
				else
				{
					PropertyService.Set("Unity.Connection", false);
					return false;
				}
			}
			catch
			{
				PropertyService.Set("Unity.Connection", true);
				return false;
			}

		}
Beispiel #20
0
        /// <summary>
        /// 状态检测方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void stadtimer_Tick(object sender, EventArgs e)
        {
            System.Net.NetworkInformation.Ping        p       = new System.Net.NetworkInformation.Ping();
            System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
            options.DontFragment = true;
            string data = "Test Data!";

            byte[] buffer  = Encoding.ASCII.GetBytes(data);
            int    timeout = 2000; // Timeout 时间,单位:毫秒

            //检查网络连接
            try
            {
                System.Net.NetworkInformation.PingReply reply = p.Send("baidu.com", timeout, buffer, options);
                if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
                {
                    stat.line          = true;
                    netLine.Text       = "网络已连接";
                    netLine.Foreground = Brushes.Green;
                }
                else
                {
                    stat.line          = false;
                    netLine.Text       = "网络连接已断开";
                    netLine.Foreground = Brushes.Red;
                }
            }
            catch
            {
                stat.line          = false;
                netLine.Text       = "网络异常,请联系管理员";
                netLine.Foreground = Brushes.Red;
            }

            if (stat.line == true)
            {
                //从网络获取机器状态
                HttpBLL httpbll = new HttpBLL();
                JSONBLL jsonbll = new JSONBLL();

                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("id", ConfigurationManager.AppSettings["id"]);

                string str = httpbll.GetResponseString(httpbll.CreatePostHttpResponse(ConfigurationManager.AppSettings["machine"], dic));

                if (str != null)
                {
                    JObject jo = JsonConvert.DeserializeObject <JObject>(str);

                    if (jo["code"].ToString() == "200")
                    {
                        JObject jo1;
                        string  str1 = jo["machine"].ToString();
                        if (str1 != null)
                        {
                            jsonbll.jsonToJobject(str1, out jo1);
                            stat.stat = jo1["nowStatus"].ToString();
                        }
                        else
                        {
                            stat.stat = "查无此机,若要正常使用,请检查配置文件与服务器";
                        }
                    }
                    else
                    {
                        stat.stat = "意外错误,未能与服务器正常通信";
                    }
                }
                else
                {
                    stat.stat = "意外错误,通信失败";
                }
            }
            else
            {
                stat.stat = "连接失败";
            }

            pageRemain.Text = App.set.remainPageNum.ToString();

            try
            {
                PrintServer ps    = new PrintServer();
                PrintQueue  queue = ps.GetPrintQueue(ConfigurationManager.AppSettings["printer"]);
                printerStaTxt.Text = queue.QueueStatus.ToString();
                ps.Dispose();
                queue.Dispose();
            }
            catch
            {
                printerStaTxt.Text = "打印服务未启动";
            }
        }
        //Traceroute inspired by: http://coding.infoconex.com/post/C-Traceroute-using-net-framework.aspx
        public void Traceroute(object bResolve)
        {
            bool bRes = (bool)bResolve;
            try
            {
                string sHostName = "",sFormat = "";
                if(bRes)
                    sFormat = "{0}\t{1} ms\t{2}\t{3}";
                else
                    sFormat = "{0}\t{1} ms\t{2}";

                System.Net.IPAddress ipAddress;
                try
                {
                    ipAddress = System.Net.Dns.GetHostEntry(RemoteIP).AddressList[0];
                }
                catch (Exception)
                {
                    ipAddress = System.Net.IPAddress.Parse(RemoteIP);
                    //throw;
                }
                using (System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping())
                {
                    System.Net.NetworkInformation.PingOptions pingOptions = new System.Net.NetworkInformation.PingOptions();
                    System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
                    byte[] bytes = new byte[32];
                    pingOptions.DontFragment = true;
                    pingOptions.Ttl = 1;
                    int maxHops = 30;
                    fHelper.ExecuteThreadSafe(() =>
                    {
                        fHelper.textBox1.Text = string.Format(
                            "Tracing route to {0} over a maximum of {1} hops:",
                            ipAddress,
                            maxHops);
                        fHelper.textBox1.Text += "\r\n";
                    });
                    for (int i = 1; i < maxHops + 1; i++)
                    {
                        stopWatch.Reset();
                        stopWatch.Start();
                        System.Net.NetworkInformation.PingReply pingReply = pingSender.Send(
                            ipAddress,
                            5000,
                            new byte[32], pingOptions);
                        stopWatch.Stop();
                        if (bRes)
                        {
                            try
                            {
                                sHostName = System.Net.Dns.GetHostEntry(pingReply.Address).HostName;
                            }
                            catch (Exception)
                            {
                                sHostName = "unknown";
                            }
                        }
                        fHelper.ExecuteThreadSafe(() =>
                        {
                            fHelper.textBox1.Text += string.Format(sFormat,
                            i,
                            stopWatch.ElapsedMilliseconds,
                            pingReply.Address,
                            sHostName);
                            fHelper.textBox1.Text += "\r\n";
                        });
                        if (pingReply.Status == System.Net.NetworkInformation.IPStatus.Success)
                        {
                            fHelper.ExecuteThreadSafe(() =>
                            {
                                fHelper.textBox1.Text += "Trace complete.";
                            });
                            break;
                        }
                        pingOptions.Ttl++;
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message + ": " + RemoteIP);
            }
        }
Beispiel #22
0
        //This function is for testing a node on the network
        private void testConnection(object sender, System.ComponentModel.DoWorkEventArgs e)
        {
            //listbox.TopIndex = listbox.Items.Count - 1;
            listBox1.Invoke(new Action(() => listBox1.Items.Add(" Start! ")));
            //bool to determin if the while loop has run once for things I want to do ONE time
            bool checkedOS = true;
            string osVersion = null;
            int maxMem = 104857600;
            int pingTimeOut = -1;

            bool canConnect = false;
            while (true)
            {
                //Check to see if the worker has been cancled.
                if (worker.CancellationPending == true)
                {
                    worker.Dispose();
                    return;
                }

                //This is to warn if the program is eating up TOO much memory, 50MB is the warning.
                if(System.Diagnostics.Process.GetCurrentProcess().WorkingSet64 >= maxMem)
                {
                    string answerToContinue = MessageBox.Show("Warning, the application is taking up 100MB or more, would you like to continue? If you say yes then the error will show again at " + maxMem + " bytes", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation).ToString();
                    if(answerToContinue == "No")
                    {
                        stopButton_Click();
                        return;
                    }
                    else
                    {
                        maxMem = maxMem * 2;
                    }

                    //Null item
                    answerToContinue = null;
                }

                //Do this once if check OS is checked
                if (checkedOS == true && attemptOSVersion.Checked == true)
                {
                    osVersion = GetOsVersion(ipAddressBox.Text);
                    checkedOS = false;
                }
                //Check to see if they want auto scroll, if so then scroll
                if(autoScroll.Checked == true)
                {
                    listBox1.Invoke(new Action(() => listBox1.TopIndex = listBox1.Items.Count - 1));
                }

                //Get ping info
                string pingInfo = "";
                string pingTTL = "";
                System.Net.IPAddress hostIP = null;

                //bool to stop continuing ping if host cannot be converted to IP
                if (ipAddressBox.Text != "")
                {
                    try
                    {
                        System.Net.NetworkInformation.Ping myPing = new System.Net.NetworkInformation.Ping();
                        String host = null;

                        if (forceIPv4 == true)
                        {
                            host = Array.FindAll(System.Net.Dns.GetHostEntry(ipAddressBox.Text).AddressList, a => a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)[0].ToString();
                        }
                        else
                        {
                            host = ipAddressBox.Text;
                        }

                        byte[] buffer = new byte[32];
                        System.Net.NetworkInformation.PingOptions pingOptions = new System.Net.NetworkInformation.PingOptions();

                        System.Net.NetworkInformation.PingReply reply = null;
                        try
                        {
                            System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
                            stopwatch.Start();
                            reply = myPing.Send(host, 1000, buffer, pingOptions);
                            stopwatch.Stop();
                            pingTimeOut = stopwatch.Elapsed.Milliseconds;
                            hostIP = reply.Address;
                        }
                        catch(Exception)
                        {
                            //MessageBox.Show("Error sending ping: " + ex.Message);
                            listBox1.Invoke(new Action(() => listBox1.Items.Add("Cannot find IP address of the hostname: " + ipAddressBox.Text)));
                            canConnect = false;

                        }

                        if (/*reply != null &&*/ reply.Status.ToString().Contains("Success"))
                        {

                            canConnect = true;

                            //IPv6 doesn't have TTL, check for that
                            if(/*pingTTL == null*/ reply.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                            {

                                pingTTL = null;
                            }
                            else
                            {
                                pingTTL = reply.Options.Ttl.ToString();
                            }

                            pingInfo = reply.RoundtripTime.ToString();
                            //MessageBox.Show(pingInfo);

                        }

                    }

                    catch (Exception)
                    {
                       //Failed to get host or ping
                    }
                }
                else
                {
                    canConnect = false;
                }

                if (canConnect == true)
                {
                    if (showFailsOnly.Checked == false)
                    {
                        //This is what's printed to the screen
                        //invoke because this is in another thread!
                        try
                        {
                            this.Invoke(new Action(() => this.BackColor = System.Drawing.Color.Green));
                        }
                        catch (Exception)
                        {

                        }

                        listBox1.Invoke(new Action(() => listBox1.Items.Add("IP Address: " + hostIP)));
                        listBox1.Invoke(new Action(() => listBox1.Items.Add(DateTime.Now + "  " + (ipAddressBox.Text) + " is " + "UP")));
                        listBox1.Invoke(new Action(() => listBox1.Items.Add("Round Trip Time: " + pingInfo)));
                        if (pingTimeOut >= 0) { listBox1.Invoke(new Action(() => listBox1.Items.Add(pingTimeOut.ToString() + " milliseconds"))); }

                        try
                        {
                            if (pingTTL != null || hostIP.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6) { listBox1.Invoke(new Action(() => listBox1.Items.Add("TTL: " + pingTTL))); }
                        }
                        catch (Exception)
                        {
                            //
                        }
                        //Get OS Version info if the user selects it
                        if (attemptOSVersion.Checked == true) { if (osVersion != null) { listBox1.Invoke(new Action(() => listBox1.Items.Add("OS: " + osVersion))); } }
                        listBox1.Invoke(new Action(() => listBox1.Items.Add(" ")));

                        //Set max timeout
                        if(Convert.ToInt32(maxTimeOutCounter.Text) < pingTimeOut)
                        {
                            maxTimeOutCounter.Invoke(new Action(() => maxTimeOutCounter.Text = pingTimeOut.ToString()));
                        }
                    }

                    //Tick Succsess
                    succeedCounter.Invoke(new Action(() => succeedCounter.Text = (Convert.ToInt32(succeedCounter.Text) + 1).ToString() ));

                }
                else
                {
                    this.Invoke(new Action(() => this.BackColor = System.Drawing.Color.Red));
                    //invoke because this is in another thread!
                    listBox1.Invoke(new Action(() => listBox1.Items.Add("IP Address: " + hostIP)));
                    listBox1.Invoke(new Action(() => listBox1.Items.Add(DateTime.Now + "  " + (ipAddressBox.Text) + " is " + "DOWN")));
                    listBox1.Invoke(new Action(() => listBox1.Items.Add(" ")));
                    //Tick fail
                    failCounter.Invoke(new Action(() => failCounter.Text = (Convert.ToInt32(failCounter.Text) + 1).ToString()));
                }
                //timeout

                //Get the reliability, succseed / total
                reliabilityCounter.Invoke(new Action(() => reliabilityCounter.Text = Math.Round((Convert.ToDouble(succeedCounter.Text) / (Convert.ToDouble(succeedCounter.Text) + Convert.ToDouble(failCounter.Text))) * 100, 2).ToString() + "%"));

                //update chart
                updateChart();
                if(userWaitTime != 0)
                {
                    System.Threading.Thread.Sleep(userWaitTime * 1000);
                }

                GC.Collect();

            }
        }
Beispiel #23
0
 public static bool Ping(string ip)
 {
     try
     {
         using (System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping())
         {
             System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
             options.DontFragment = true;
             string data = "MissionPlanner";
             byte[] buffer = Encoding.ASCII.GetBytes(data);
             int timeout = 500;
             System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, options);
             if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
                 return true;
             else
                 return false;
         }
     }
     catch
     {
         return false;
     }
 }
Beispiel #24
0
        public string GetOsVersion(string ipAddress)
        {
            if(ipAddressBox.Text == "") { return "ADDRESS EMPTY"; }
            System.Net.NetworkInformation.Ping myPing = new System.Net.NetworkInformation.Ping();
            String host = ipAddressBox.Text;
            byte[] buffer = new byte[32];
            //MessageBox.Show(timeout.ToString());
            System.Net.NetworkInformation.PingOptions pingOptions = new System.Net.NetworkInformation.PingOptions();
            System.Net.NetworkInformation.PingReply reply;
            try {
                reply = myPing.Send(host, 1000, buffer, pingOptions);
            }
            catch (Exception ex)
            {
                //FIX!!
                return ex.Message;
            }

            //Null out variables not needed
            myPing = null;
            host = null;
            buffer = null;
            pingOptions = null;

             int pingTTL = reply.Options.Ttl;
            reply = null;
            GC.Collect();

            //Only attempt this if it's a Windows host
            if (pingTTL <= 128 && pingTTL > 64)
                {

                try
                {
                    //This will display the message to the user letting them know the program is getting the OS
                    listBox1.Items.Add("Trying to get OS information, this may take a second or two");
                    //Check to see if the port is open before you access the registry, if not the .NET API will freeze and sometimes crash

                        using (var reg = Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, ipAddress))
                        using (var key = reg.OpenSubKey(@"Software\Microsoft\Windows NT\CurrentVersion\"))
                        {
                            return string.Format("Name:{0}, Version:{1}", key.GetValue("ProductName"), key.GetValue("CurrentVersion"));
                        }

                }
                catch(Exception)
                {

                        return "Windows";

                }

                }
                else if (pingTTL <= 64)
                {
                        return "Linux";
                }
                else if (pingTTL <= 255 && pingTTL >= 129)
                {
                    return "Unix";
                }
                else
                {
                    return "Error getting OS";
                }
        }
 public System.Threading.Tasks.Task <System.Net.NetworkInformation.PingReply> SendPingAsync(string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options)
 {
     throw null;
 }
Beispiel #26
0
 public PingReply Send(string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options)
 {
     throw null;
 }