/// <summary> /// Ping応答があるかを返します。 /// </summary> /// <param name="host">送信先のホスト</param> /// <param name="toutms">タイムアウト時間(ms)</param> /// <returns>結果(リプライあり=true, リプライなし=false)</returns> public bool IsPingReply(String host, int toutms) { bool rt = true; System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); try { LogPrint("PING " + host); System.Net.NetworkInformation.PingReply reply = p.Send(host, toutms); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { LogPrint("PING 応答 - From[" + reply.Address.ToString() + "], Size[" + reply.Buffer.Length.ToString() + "], Time[" + reply.RoundtripTime.ToString() + "ms], TTL[" + reply.Options.Ttl.ToString() + "]"); } else { LogPrint("PING 失敗 - " + reply.Status.ToString()); rt = false; } } catch { rt = false; } p.Dispose(); return(rt); }
}/////////////////////////// public bool pingHost(string host) { if (!String.IsNullOrEmpty(host)) { try { System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingReply = ping.Send(host); return(true); } catch (System.Net.NetworkInformation.PingException e) { //MessageBox.Show(e.Message); return(false); } } else { return(false); } }/////////////////////////////////////////
private static bool IsServerConnected(string connectionString) { using (SqlConnection connection = new SqlConnection(connectionString)) { try { System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply reply = p.Send(connection.DataSource); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { connection.Open(); return(true); } else { return(false); } } catch (SqlException err) { MessageBox.Show(err.Message); return(false); } } }
//static async void CallMethod() //{ // await InternetVarmi2(); // //InternetVarmi2(); //} public bool InternetVarmi2() { try { System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingDurumu = ping.Send("www.google.com");//IPAddress.Parse("64.15.112.45")); if (pingDurumu.Status == System.Net.NetworkInformation.IPStatus.Success) { ivarmi = true; return(true); //Console.WriteLine("İnternet bağlantısı var"); } else { ivarmi = false; return(false); //Console.WriteLine("İnternet bağlantısı yok"); } //Console.ReadKey(); //return true; } catch { ivarmi = false; return(false); } }
protected void PingTest(CancellationToken token) { System.Net.NetworkInformation.Ping pingClass = new System.Net.NetworkInformation.Ping(); while (token.IsCancellationRequested == false) { System.Net.NetworkInformation.PingReply pingReply = pingClass.Send(IPAddress); //if ip is valid run checks else if (pingReply.Status == System.Net.NetworkInformation.IPStatus.Success) { if (IsOnline != true) { IsOnline = true; Log(log.Info, "{0} is online!", IPAddress.ToString()); RaiseOnlineChanged(EventArgs.Empty); } } else { if (IsOnline == true) { IsOnline = false; Log(log.Info, "{0} has gone offline!", IPAddress.ToString()); RaiseOnlineChanged(EventArgs.Empty); } } Thread.Sleep(5000); } }
private Boolean connected(String path) { String hostName = path.Split('\\')[2]; System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pr = null; try { pr = p.Send(hostName, 1000); } catch (System.Net.NetworkInformation.PingException) { return(false); //throw new ExportProgramsException("Ping exception", pEx); } catch (Exception) { return(false); } switch (pr.Status) { case System.Net.NetworkInformation.IPStatus.Success: return(true); case System.Net.NetworkInformation.IPStatus.TimedOut: ExportProgramsException ex = new ExportProgramsException("Network timout on " + path); throw ex; case System.Net.NetworkInformation.IPStatus.DestinationHostUnreachable: return(false); case System.Net.NetworkInformation.IPStatus.Unknown: return(false); default: return(false); } }
/// <summary> /// Описание нашей системы /// </summary> public void DescribeSystem() { Console.Title = "Сканер локальной сети"; Console.CursorVisible = false; Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\n---------------------------------Этот компьютер---------------------------------"); //-----------------------------------------Проверка соединения с интернетом------------------------------------------------------- string proverka_soedineniya_s_internetom1 = ""; try { System.Net.NetworkInformation.Ping proverka_pinga = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply proverka_pingReply1 = proverka_pinga.Send("google.com"); proverka_soedineniya_s_internetom1 = proverka_pingReply1.Status.ToString(); if (proverka_soedineniya_s_internetom1 == "Success") { proverka_soedineniya_s_internetom1 = "Соединение присутствует"; } else { proverka_soedineniya_s_internetom1 = "Соединение отсутствует"; } } catch { proverka_soedineniya_s_internetom1 = "Соединение отсутствует"; } //-------------------------------------------------------------------------------------------------------------------------------- Console.WriteLine("Имя компьютера: " + host + "\t\tСостояние подключения к интернету:"); Console.WriteLine("IP-адрес компьютера: " + ip_addres + "\t" + proverka_soedineniya_s_internetom1); Console.WriteLine("\n--------------------------------------------------------------------------------"); }
private void carRateToMysql() { while (getTotalCarNumone() != 0 && getTotalCarNumtwo() != 0) { ratetotal = (double)getTotalOkCarNum() / getTotalCarNum(); rateone = (double)getTotalOkCarNumone() / getTotalCarNumone(); ratetwo = (double)getTotalOkCarNumtwo() / getTotalCarNumtwo(); string sql = "insert into finalcarinfo values('" + DateTime.Now.ToString() + "','" + getTotalCarNum() + "','" + ratetotal.ToString("0.00%") + "','" + getTotalCarNumone() + "','" + rateone.ToString("0.00%") + "','" + getTotalCarNumtwo() + "','" + ratetwo.ToString("0.00%") + "')"; string sqldel = "delete from finalcarinfo"; //检测网络连接状态,网络连接成功后,写入数据 System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingStatus = ping.Send(IPAddress.Parse("202.108.22.5"), 1000);//ping 百度的IP地址 if (pingStatus.Status == System.Net.NetworkInformation.IPStatus.Success) { sqlOperate.MySqlCom(sqldel); sqlOperate.MySqlCom(sql); } Thread.Sleep(300000); } }
public static bool Send(string url, out System.Net.NetworkInformation.PingReply reply) { reply = null; using (System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping()) { try { reply = pingSender.Send(url); if (reply?.Status != System.Net.NetworkInformation.IPStatus.Success) { return(false); //Console.WriteLine("Address: {0}", reply.Address.ToString()); //Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime); //Console.WriteLine("Time to live: {0}", reply.Options.Ttl); //Console.WriteLine("Don't fragment: {0}", reply.Options.DontFragment); //Console.WriteLine("Buffer size: {0}", reply.Buffer.Length); } return(true); } // ReSharper disable once UnusedVariable catch (Exception ex) { Logger.Instance.AppendException(ex); // ReSharper disable once RedundantJumpStatement return(false); } } }
public bool Ping(string Address, int Timeout) { if (Address == null) { return(false); } Address = Address.Trim(); if ((Address == "") || (Timeout < 1)) { return(false); } Options.DontFragment = true; try { Reply = Pinger.Send(Address, Timeout, Packet, Options); } catch (System.Exception Excpt) { Err.Add(Excpt); return(false); } if (Reply.Status != System.Net.NetworkInformation.IPStatus.Success) { return(false); } else { return(true); } }
/// <summary> /// Verifies if the supplied proxy and port can be connected to /// Returns true if the proxy was OK /// </summary> /// <returns></returns> public async Task <bool> VerifyProxy(Proxy _proxy, int timeout) { // Start the verification process in a new thread/task return(await Task.Run(() => { // Open a new ping request to see if we can reach the IP and port in question System.Net.NetworkInformation.Ping pinger = new System.Net.NetworkInformation.Ping(); try { // Get the ping reply System.Net.NetworkInformation.PingReply reply = pinger.Send(_proxy.Prox, timeout); // Check if the reply was valid if (reply == null) { return false; } // Return status as bool return (reply.Status == System.Net.NetworkInformation.IPStatus.Success); } catch (Exception ex) { return false; } })); }
Boolean CanPing(String compi) { System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply reply = ping.Send(compi); return(reply.Status.ToString() == "Success"); }
private void Ping_PingReplied(IPAddress ip, System.Net.NetworkInformation.PingReply reply) { string format = "{0} : {1}ms : {2}"; AddtoLog(LogType.PING, string.Format(format, ip.ToString(), reply.RoundtripTime, reply.Status.ToString())); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { Dispatcher.BeginInvoke(new Action(() => { NetworkNodesFound++; SearchProgressMaximum += (portRangeStop - portRangeStart); // Increment number of ports to probe }), System.Windows.Threading.DispatcherPriority.Background, new object[] { }); for (var p = portRangeStart; p < ((portRangeStop - portRangeStart) + portRangeStart); p++) { if (!stop.WaitOne(0, true)) { var info = new TestInfo(); info.Address = reply.Address.ToString(); info.Port = p; TestPort(info); //ThreadPool.QueueUserWorkItem(new WaitCallback(TestPort), info); } else { break; } } } }
void timer1_Tick(object sender, EventArgs e) { timer1.Stop(); try { System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply rep = ping.Send("192.168.2.75", 1000); if (rep.Status == System.Net.NetworkInformation.IPStatus.BadDestination) { listView1.Items[4].ImageIndex = 3; } else if (rep.Status == System.Net.NetworkInformation.IPStatus.TimedOut) { listView1.Items[4].ImageIndex = 1; } else if (rep.Status == System.Net.NetworkInformation.IPStatus.Success) { listView1.Items[4].ImageIndex = 2; } else { listView1.Items[4].ImageIndex = 0; } listView1.Items[5].ImageIndex = DB.GetInstance().Connection.State == ConnectionState.Open ? 2 : 1; } catch { } timer1.Start(); }
private void button4_Click(object sender, EventArgs e) { 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 = Encoding.ASCII.GetBytes(data); int timeout = 120; try { System.Net.NetworkInformation.PingReply reply = pingSender.Send(txtServer.Text, timeout, buffer, options); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { System.Windows.Forms.MessageBox.Show("Rechner verfügbar!"); } else { System.Windows.Forms.MessageBox.Show("Rechner nicht erreichbar!"); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show("Ping-Fehler: " + ex.Message); } }
public static string GetIPAddress() { System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions(); options.DontFragment = true; byte[] buffer = new byte[0]; int timeout = 300; // Timeout 时间,单位:毫秒 string strIP = System.Configuration.ConfigurationManager.AppSettings["IPAddress"]; string strWebIP = System.Configuration.ConfigurationManager.AppSettings["WebIPAddress"]; System.Net.NetworkInformation.PingReply reply = p.Send(strIP, timeout, buffer, options); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { return(strIP); } else { return(strWebIP); } }
protected void PingCallback(object sender, System.Net.NetworkInformation.PingCompletedEventArgs e) { // If the operation was canceled, display a message to the user. if (e.Cancelled) { Console.WriteLine("Ping canceled."); Disconnect(((ClientConnection)e.UserState).ThisID); } // If an error occurred, display the exception to the user. if (e.Error != null) { Console.WriteLine("Ping failed:"); Disconnect(((ClientConnection)e.UserState).ThisID); } System.Net.NetworkInformation.PingReply reply = e.Reply; int id = ((int)e.UserState); Clients[id].Ping = (int)(reply.RoundtripTime / 2); PacketDesc_Ping pkt = new PacketDesc_Ping(); pkt.PacketTarget = EConnectionType.CLIENT; pkt.PacketOriginClientID = UniqueID; pkt.ToServerLatency = Clients[id].Ping; // send clients one way to server latency SendPacketToClient(pkt, id); }
private void PingTerminal() { bool result = false; string exceptionMessage = null; try { using (System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping()) { System.Net.NetworkInformation.PingReply pingReply = ping.Send(Program.m_sSmartpayIP); result = (pingReply.Status == System.Net.NetworkInformation.IPStatus.Success); } } catch (Exception ex) { exceptionMessage = ex.Message; } MessageBox.Show(result.ToString()); /* * MessageBox.Show( * this, * String.Format( * "Result: {0}" + Environment.NewLine + * "Additional Info: {1}", * result ? "Success" : "Failed", * exceptionMessage ?? "None"), * "Name", * MessageBoxButtons.OK, * MessageBoxIcon.Information); */ }
/// <summary> /// Sends packets to host with itteration count /// </summary> /// <param name="host"></param> /// <param name="itterations"></param> /// <returns></returns> public void Send(string host, int itterations = 4) { for (int i = 0; i < itterations; i++) { this._pr = this._p.Send(host); this._pingStatus = this._pr.Status; if (this._pingStatus == System.Net.NetworkInformation.IPStatus.Success) { this._lastPingTime = this._pr.RoundtripTime; this._totalPingTime += this._lastPingTime; var d = new Dictionary <string, long>(); d.Add("LastPingTime", this._lastPingTime); d.Add("TotalPingTime", this._totalPingTime); this._allPingTimes.Add(d); this._allStatuses.Add(this._pingStatus); } else { throw new System.Net.NetworkInformation.PingException(host + " could not be reached!"); } } }
/// <summary> /// 通过Ping命令测试仪器是否开机 /// <param name="ipAddress">IP地址</param> /// <param name="timeout">timeout时间(毫秒)</param> /// </summary> public static bool PingDevice(string ipAddress, int timeout) { //通过Ping命令测试仪器是否开机 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!"; byte[] buffer = Encoding.ASCII.GetBytes(data); ErrorString = null; try { System.Net.NetworkInformation.PingReply reply = p.Send(ipAddress, timeout, buffer, options); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) //能够Ping通,返回True { return(true); } else { return(false); } } catch (Exception) { return(false); } }
static bool Internet_Check() { //http://dobon.net/vb/dotnet/internet/ping.html System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); //Pingを送信する try { System.Net.NetworkInformation.PingReply reply = p.Send("api.twitter.com", 3000); //解放 p.Dispose(); //結果を取得しreturn if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { return(true); } else { return(false); } } //もしpingを送信できない場合はfalseを返す catch (System.Net.NetworkInformation.PingException) { return(false); } }
/// <summary> /// 利用Ping方法确定是否可以通过网络访问远程计算机 /// </summary> /// <param name="status">网络状态</param> /// <param name="ipAddressOrHostName">默认是www.baidu.com</param> /// <param name="timeout">默认是1000毫秒</param> /// <returns></returns> public static bool PingIsConnectedInternet(out System.Net.NetworkInformation.IPStatus status, string ipAddressOrHostName = "www.baidu.com", int timeout = 1000) { 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 = "aa"; byte[] buffer = Encoding.ASCII.GetBytes(data); //Wait seconds for a reply. status = System.Net.NetworkInformation.IPStatus.Unknown; try { System.Net.NetworkInformation.PingReply reply = p.Send(ipAddressOrHostName, timeout, buffer, options); status = reply.Status; if (status == System.Net.NetworkInformation.IPStatus.Success) { return(true); } else { return(false); } } catch { return(false); } }
public JsonResult Ping(string nombreInstancia) { JsonResponse json = new JsonResponse(); try { System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply result = ping.Send(nombreInstancia); if (result.Status.ToString().ToLower() == "success") { json.Data = "Prendido"; } else { json.Data = "Apagado"; } json.IsSuccess = true; } catch (Exception ex) { json.Message = ex.Message; json.IsFail = true; } return(Json(json, JsonRequestBehavior.AllowGet)); }
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); } }
private void pingButton_Click(object sender, EventArgs e) { System.Net.IPAddress address; if (!System.Net.IPAddress.TryParse(localIPTextBox.Text, out address)) { MessageBox.Show("Invalid!!"); return; } try { using (System.Net.NetworkInformation.Ping tmpPing = new System.Net.NetworkInformation.Ping()) { System.Net.NetworkInformation.PingReply reply = tmpPing.Send(address, 1); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { MessageBox.Show("Success!!"); } else { MessageBox.Show("Failed!!"); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ovenInfoToAliMysql() { while (true) { Thread.Sleep(600000); chimneyTem[0] = Convert.ToString(operatePlc.readPlcDbdValues("10.228.140.46", 0, 3, 92, 0)); chimneyTem[1] = Convert.ToString(operatePlc.readPlcDbdValues("10.228.140.54", 0, 3, 92, 0)); chimneyTem[2] = Convert.ToString(operatePlc.readPlcDbdValues("10.228.140.98", 0, 3, 92, 0)); chimneyTem[3] = Convert.ToString(operatePlc.readPlcDbdValues("10.228.141.38", 0, 3, 92, 0)); chimneyTem[4] = Convert.ToString(operatePlc.readPlcDbdValues("10.228.141.46", 0, 3, 92, 0)); chimneyTem[5] = Convert.ToString(operatePlc.readPlcDbdValues("10.228.141.82", 0, 3, 92, 0)); chimneyTem[6] = Convert.ToString(operatePlc.readPlcDbdValues("10.228.141.126", 0, 3, 92, 0)); tnvTem[0] = Convert.ToString(operatePlc.readPlcDbwValue("10.228.140.46", 0, 3, 294, 2)); tnvTem[1] = Convert.ToString(operatePlc.readPlcDbwValue("10.228.140.54", 0, 3, 294, 2)); tnvTem[2] = Convert.ToString(operatePlc.readPlcDbwValue("10.228.140.98", 0, 3, 294, 2)); tnvTem[3] = Convert.ToString(operatePlc.readPlcDbwValue("10.228.141.38", 0, 3, 294, 2)); tnvTem[4] = Convert.ToString(operatePlc.readPlcDbwValue("10.228.141.46", 0, 3, 294, 2)); tnvTem[5] = Convert.ToString(operatePlc.readPlcDbwValue("10.228.141.82", 0, 3, 294, 2)); tnvTem[6] = Convert.ToString(operatePlc.readPlcDbwValue("10.228.141.126", 0, 3, 294, 2)); string sql = "insert into oveninfo (DA,ED1TNV,ED1CHIMNEY,ED2TNV,ED2CHIMNEY,PVCTNV,PVCCHIMNEY,PR1TNV,PR1CHIMNEY,PR2TNV,PR2CHIMNEY,TC1TNV,TC1CHIMNEY,TC2TNV,TC2CHIMNEY) values('" + DateTime.Now.ToString() + "','" + chimneyTem[0] + "','" + chimneyTem[1] + "','" + chimneyTem[2] + "','" + chimneyTem[3] + "','" + chimneyTem[4] + "','" + chimneyTem[5] + "','" + chimneyTem[6] + "','" + tnvTem[0] + "','" + tnvTem[1] + "','" + tnvTem[2] + "','" + tnvTem[3] + "','" + tnvTem[4] + "','" + tnvTem[5] + "','" + tnvTem[6] + "')"; //检测网络连接状态,网络连接成功后,写入数据 System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingStatus = ping.Send(IPAddress.Parse("202.108.22.5"), 1000);//ping 百度的IP地址 if (pingStatus.Status == System.Net.NetworkInformation.IPStatus.Success) { sqlOperate.MySqlCom(sql); } } }
/// <summary> /// bug there will be a bug if you .net is 2.0sub /// </summary> /// <returns></returns> public long Ping(string ip) { IPAddress ipAddress = IPAddress.Parse(ip); System.Net.NetworkInformation.Ping tempPing = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply temPingReply = tempPing.Send(ipAddress); return(temPingReply.RoundtripTime); //private int pingTime; //private Ping p; //private float timeOut = 1; //private float lastTime; //void Start() //{ // StartCoroutine(Ping()); //} //IEnumerator Ping() //{ // p = new Ping("127.0.0.1"); // lastTime = Time.realtimeSinceStartup; // while (!p.isDone && Time.realtimeSinceStartup - lastTime < 1) // { // yield return null; // } // pingTime = p.time; // p.DestroyPing(); // yield return new WaitForSeconds(1); // StartCoroutine(Ping()); // } }
public 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(); 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); } } catch { return(false); } }
public bool IsTerminalConnected(Terminal terminal) { System.Net.NetworkInformation.Ping pinger = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingReply = pinger.Send(terminal.IPAddress); return(pingReply.Status == System.Net.NetworkInformation.IPStatus.Success); }
/// <summary> /// /// </summary> /// <param name="host"></param> /// <param name="port"></param> /// <param name="timeout"></param> /// <param name="format"></param> /// <returns></returns> public static DomainResult PingDomain(String host, int port, int timeout = 12000, String format = "seconds") { System.Net.Sockets.TcpClient tcpClient = new System.Net.Sockets.TcpClient(); tcpClient.SendTimeout = timeout; double status; System.Net.NetworkInformation.PingReply reply = null; System.Net.NetworkInformation.PingException pingEx = null; try { double start = Tools.DateUtils.GetUnixTimestamp(DateTime.Now); tcpClient.Connect(host, port); double end = Tools.DateUtils.GetUnixTimestamp(DateTime.Now); status = (end - start) * 1000; status = Math.Floor(status); double tcpConnectLatency = format == "seconds" ? status * 0.001 : status; System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping(); try { reply = pingSender.Send(host); } catch (System.Net.NetworkInformation.PingException pe) { pingEx = pe; } catch { } return(new DomainResult(tcpConnectLatency, reply, pingEx)); } catch { return(new DomainResult(-1, reply)); } }
private static IPAddress FindBurtsIPAddress(string localIPaddr) { IPAddress burtsIP = localhost; try { System.Net.NetworkInformation.Ping p1 = new System.Net.NetworkInformation.Ping(); try { PR = p1.Send("burt", 250); if (PR.Status.ToString().Equals("Success")) return PR.Address; } catch (Exception e) { }; IPAddress localIP = IPAddress.Parse(localIPaddr); byte[] addrBytes = localIP.GetAddressBytes(); for (byte n = 0; n < 254; n++) { int numBytes = addrBytes.GetLength(0); addrBytes.SetValue(n, numBytes - 1); IPAddress lookupIPAddr = new IPAddress(addrBytes); try { PR = p1.Send(lookupIPAddr, 1000 / 254); if (PR.Status.ToString().Equals("Success")) return PR.Address; } catch (Exception e) { }; if (PR.Status.ToString().Equals("Success")) { Console.WriteLine(PR.Status.ToString()); } } } catch(System.Net.Sockets.SocketException e) { Console.WriteLine("SocketException caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } catch(Exception e) { Console.WriteLine("Exception caught!!!"); Console.WriteLine("Source : " + e.Source); Console.WriteLine("Message : " + e.Message); } return burtsIP; }