public string ToCIDR() { if (Valid == false) { return(""); } if (IsV4) { return(m_IP.ToString() + "/" + NetMask2bitMaskV4(m_Mask)); } else { return(""); // TOFIX, unknown how to format. When implemented, read comment in NetworkLockWfp::OnUpdateIps } }
public virtual Int64 Ping(IpAddress host, int timeoutSec) { if ((host == null) || (host.Valid == false)) { return(-1); } 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. byte[] buffer = RandomGenerator.GetBuffer(32); int timeout = timeoutSec * 1000; PingReply reply = pingSender.Send(host.ToString(), timeout, buffer, options); if (reply.Status == IPStatus.Success) { return(reply.RoundtripTime); } else { return(-1); } }
/* * public void Start() * { * T = new System.Threading.Thread(new ThreadStart(this.Run)); * T.Priority = ThreadPriority.Lowest; * T.Start(); * } */ public void Run() { RouteScope routeScope = null; try { IpAddress ip = Server.IpsEntry.FirstPreferIPv4; if ((ip == null) || (ip.Valid == false)) { throw new Exception("Invalid ip"); } routeScope = new RouteScope(ip.ToString()); Int64 result = Platform.Instance.Ping(ip, 3); Engine.Instance.JobsManager.Latency.PingResult(Server, result); } catch (Exception) { Engine.Instance.JobsManager.Latency.PingResult(Server, -1); } finally { if (routeScope != null) { routeScope.End(); } lock (Engine.Instance.JobsManager.Latency.Jobs) { Engine.Instance.JobsManager.Latency.Jobs.Remove(this); } } }
/* * public void Start() * { * T = new System.Threading.Thread(new ThreadStart(this.Run)); * T.Priority = ThreadPriority.Lowest; * T.Start(); * } */ public void Run() { RouteScope routeScope = null; try { IpAddress ip = Server.IpsEntry.FirstPreferIPv4; if ((ip == null) || (ip.Valid == false)) { throw new Exception("Invalid ip"); } routeScope = new RouteScope(ip.ToString()); Int64 result = Platform.Instance.Ping(ip, Engine.Instance.Storage.GetInt("pinger.timeout")); if ((Engine.Instance == null) || (Engine.Instance.JobsManager == null) || (Engine.Instance.JobsManager.Latency == null)) { return; // Avoid unidentified crash } Engine.Instance.JobsManager.Latency.PingResult(Server, result); } catch (Exception) { if ((Engine.Instance == null) || (Engine.Instance.JobsManager == null) || (Engine.Instance.JobsManager.Latency == null)) { return; // Avoid unidentified crash } Engine.Instance.JobsManager.Latency.PingResult(Server, -1); } finally { if (routeScope != null) { routeScope.End(); } if ((Engine.Instance == null) || (Engine.Instance.JobsManager == null) || (Engine.Instance.JobsManager.Latency == null)) { // Avoid unidentified crash } else { lock (Engine.Instance.JobsManager.Latency.Jobs) { Engine.Instance.JobsManager.Latency.Jobs.Remove(this); } } } }
public override bool Equals(object obj) { if (obj == null) { return(false); } IpAddress two = obj as IpAddress; if (two == null) { return(false); } return(ToString() == two.ToString()); }
/* * public void Start() * { * T = new System.Threading.Thread(new ThreadStart(this.Run)); * T.Priority = ThreadPriority.Lowest; * T.Start(); * } */ public void Run() { RouteScope routeScope = null; try { IpAddress ip = Server.IpsEntry.OnlyIPv4.First; /* * if (Server.DisplayName == "Castor") // ClodoTemp * ip = Server.IpsEntry.OnlyIPv6.First; */ if ((ip == null) || (ip.Valid == false)) { throw new Exception("Invalid ip"); } routeScope = new RouteScope(ip.ToString()); Int64 result = Platform.Instance.Ping(ip, 3); Pinger.Instance.PingResult(Server, result); } catch (Exception) { Pinger.Instance.PingResult(Server, -1); } finally { if (routeScope != null) { routeScope.End(); } lock (Pinger.Instance.Jobs) { Pinger.Instance.Jobs.Remove(this); } } }