public PingResponse(DateTime time, TypeProtocol protocol, string host, PingStatus status) { Time = time; Protocol = protocol; Host = host; Status = status; }
public PingCodeResponse(DateTime time, TypeProtocol protocol, string host, PingStatus status, int code) { Time = time; Protocol = protocol; Host = host; Status = status; Code = code; }
public void Interpret(Data d, SQLiteConnection conn) { if (d.Type != ECollectorType.Ping) { return; } if (d is ListData <PingResult> ) { ListData <PingResult> data = d as ListData <PingResult>; Dictionary <string, long> ip_to_device_id_map = new Dictionary <string, long>(); string sql = "SELECT IPAddress, DeviceID FROM Devices WHERE DateDisabled IS NULL;"; using (SQLiteCommand command = new SQLiteCommand(sql, conn)) using (SQLiteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { if (reader.IsDBNull(0) == false) { ip_to_device_id_map[reader.GetString(0)] = reader.GetInt64(1); } } } foreach (PingResult result in data.Data) { string ip = result.Address.ToString(); if (ip_to_device_id_map.TryGetValue(ip, out long device_id)) { Tuple <EStatusType, EStatusType?> ping_status = PingStatus.GetStatus(result.IsPingable, result.AvgTime); SetDeviceStatus(device_id, ping_status.Item1, PingStatus.OnlineOrOffline, string.Empty, conn); // If the device isn't pingable, make sure we clear the good-or-slow statuses as well if (result.IsPingable == false) { ClearDeviceStatus(device_id, PingStatus.GoodOrSlow, conn); } if (ping_status.Item2.HasValue) { SetDeviceStatus(device_id, ping_status.Item2.Value, PingStatus.GoodOrSlow, string.Empty, conn); } } else { ApplicationEventLog log = new ApplicationEventLog(); log.LogError($"OfflineInterpreter: unable to find device_id from {ip}"); } } } else { string json = JsonConvert.SerializeObject(d); throw new Exception($"OfflineInterpreter: data type is wrong {json}"); } }
public TCPingException(double latency, PingStatus status, string?info) { Result = new PingResult { Latency = latency, Status = status, Info = info }; }
//private void ClientlessThreadV2(Context context) //{ // var keepalive = new Thread(() => Clientless_Ping(context)); // keepalive.Start(); // try // { // while (true) // { // if (context.Socket.Poll(0, SelectMode.SelectRead)) // { // int count = context.Socket.Receive(context.Buffer.Buffer); // if (count == 0) // { // Console.WriteLine("Disconnected!"); // OnClientlessDisconnect?.Invoke(); // throw new Exception("The remote connection has been lost."); // } // context.Security.Recv(context.Buffer.Buffer, 0, count); // } // List<Packet> packets = context.Security.TransferIncoming(); // if (packets != null) // { // foreach (Packet packet in packets) // { // Dispatcher.Process(new Packet(packet)); // OnClientlessServerPacketReceive?.Invoke(packet); // if (packet.Opcode == 0x34B5) //Character teleport successfully // { // Packet answer = new Packet(0x34B6); //Teleport confirmation packet // context.Security.Send(answer); // } // } // } // if (context.Socket.Poll(0, SelectMode.SelectWrite)) // { // List<KeyValuePair<TransferBuffer, Packet>> buffers = context.Security.TransferOutgoing(); // if (buffers != null) // { // foreach (KeyValuePair<TransferBuffer, Packet> kvp in buffers) // { // TransferBuffer buffer = kvp.Key; // OnClientlessClientPacketSent?.Invoke(kvp.Value); // while (true) // { // int count = context.Socket.Send(buffer.Buffer, buffer.Offset, buffer.Size, SocketFlags.None); // buffer.Offset += count; // if (buffer.Offset == buffer.Size) // { // break; // } // Thread.Sleep(1); // } // } // } // } // } // } // catch // { // Console.WriteLine("Disconnected!"); // OnClientlessDisconnect?.Invoke(); // } //} public void TerminateConnection() { try { cl_socket.Close(); } catch { } ServerStatus = PingStatus.None; }
internal TraceStatus( int hop, PingStatus status, string source, string destination, IPAddress destinationAddress) { _status = status; Hop = hop; Source = source; Target = destination; TargetAddress = destinationAddress; }
async Task Ping() { Animation ellipsisAnimation = new Animation(t => PingStatus.Text = "waiting" + new string('.', (int)(t * 4))); PingStatus.Text = "waiting"; PingStatus.Animate("Ellipsis", ellipsisAnimation, 200, 800, null, null, () => true); bool success = await DataService.Instance.PingServerAsync(); PingStatus.AbortAnimation("Ellipsis"); PingStatus.Text = success ? "OK" : "Failed"; PingStatus.TextColor = success ? Color.Green : Color.Red; }
public async Task <IActionResult> SavePingTransaction(PingStatus pingStatus, int vehicleId) { var newVehicleTrans = new VehicleStatusTran { PingTime = DateTime.Now, Status = pingStatus, VehicleId = vehicleId }; await _vehicleStatusTransUnitOfWork.RepositoryObject.AddAsync(newVehicleTrans); await _vehicleStatusTransUnitOfWork.SaveChangesToDbAsync(); return(Ok(newVehicleTrans)); }
// Copied over from ServerConfigPage async Task Ping() { Animation ellipsisAnimation = new Animation(t => PingStatus.Text = "waiting" + new string('.', (int)(t * 4))); PingStatus.Text = "waiting"; PingStatus.Animate("Ellipsis", ellipsisAnimation, 200, 800, null, null, () => true); bool success = await DataService.Instance.PingServerAsync(); PingStatus.AbortAnimation("Ellipsis"); PingStatus.Text = success ? "OK" : "Failed"; PingStatus.TextColor = success ? Color.Green : Color.Red; // This triggers the App to recheck the server address, so the text // under PingStatus is somewhat synchronized with the IsServerAddressGood // property. It is mostly a quick hack to avoid a possible headscratcher. App.Current.ServerAddress = App.Current.ServerAddress; }
public static async Task <PingStatus> ICMPing(IPAddress ip, int timeout = 1000) { var res = new PingStatus(); if (ip == null) { return(res); } var p1 = new Ping(); var reply = await p1.SendPingAsync(ip, timeout); if (reply != null && reply.Status == IPStatus.Success) { res.Status = reply.Status; res.Address = reply.Address; res.RTT = reply.RoundtripTime; res.TTL = reply.Options.Ttl; res.bytes = reply.Buffer.Length; //Debug info var sb = new StringBuilder(); sb.AppendLine($@"Status: {res.Status}"); sb.AppendLine($@"Address: {res.Address}"); sb.AppendLine($@"RTT: {res.RTT}"); sb.AppendLine($@"TTL: {res.TTL}"); sb.AppendLine($@"Buffer size: {res.bytes}"); Debug.WriteLine(sb.ToString()); } else if (reply != null && reply.Status == IPStatus.TimedOut) { Debug.WriteLine(@"超时"); res.Status = reply.Status; } else { Debug.WriteLine(@"失败"); res.Status = IPStatus.Unknown; } return(res); }
internal TraceStatus( int hop, PingStatus status, string source, string destination, IPAddress destinationAddress) { _status = status; Hop = hop; Source = source; Target = destination; TargetAddress = destinationAddress; if (_status.Address == IPAddress.Any || _status.Address == IPAddress.IPv6Any) { Hostname = null; } else { Hostname = _status.Destination; } }
PingInfo(double expectedInterval, PingStatus status = PingStatus.OK, int defaultTimeoutInMS = 300) { }
internal PingResult(PingStatus status) { Ping = null; Status = status; }
public PingResponse() { Ping = new PingStatus("OK"); }
private void ClientlessThread() { try { while (true) { SocketError success; Packet current; cl_recv_buffer.Size = cl_socket.Receive(cl_recv_buffer.Buffer, 0, cl_recv_buffer.Buffer.Length, SocketFlags.None, out success); if (success != SocketError.Success) { if (success != SocketError.WouldBlock) { Console.WriteLine("Disconnected!"); OnClientlessDisconnect?.Invoke(); return; } } else if (cl_recv_buffer.Size > 0) { cl_security.Recv(cl_recv_buffer); } else { Console.WriteLine("Disconnected!!"); OnClientlessDisconnect?.Invoke(); return; } #region TransferIncoming List <Packet> tmp = cl_security.TransferIncoming(); if (tmp != null) { cl_packets.AddRange(tmp); } if (cl_packets.Count > 0) { using (List <Packet> .Enumerator enumerator = cl_packets.GetEnumerator()) { while (enumerator.MoveNext()) { current = enumerator.Current; Dispatcher.Process(current); OnClientlessServerPacketReceive?.Invoke(current); if (current.Opcode == 0x2001) { string module = current.ReadAscii(); if (module == "GatewayServer") { ServerStatus = PingStatus.Send; //Sets the ServerStatus to Gateway so the ping works correctly! Packet p = new Packet(0x6100, true, false); //Patch request p.WriteInt8(cl_Locale); p.WriteAscii("SR_Client"); //Service name p.WriteInt32(cl_GameVersion); cl_security.Send(p); } else if (module == "AgentServer") { ServerStatus = PingStatus.Send; Packet p = new Packet(0x6103, true, false); //Login packet p.WriteUInt32(cl_SessionID); //Session ID we got from A102 Answer p.WriteAscii(cl_Username); p.WriteAscii(cl_Password); p.WriteUInt8(cl_Locale); p.WriteUInt32(0); //Mac address p.WriteUInt16(0); //Mac address cl_security.Send(p); } } if (current.Opcode == 0xA102) { Console.WriteLine("Starting new connection to AgentServer!"); return; } } } cl_packets.Clear(); } #endregion #region TransferOutgoing List <KeyValuePair <TransferBuffer, Packet> > tmp2 = cl_security.TransferOutgoing(); if (tmp2 != null) { foreach (KeyValuePair <TransferBuffer, Packet> kvp in tmp2) { TransferBuffer key = kvp.Key; OnClientlessClientPacketSent?.Invoke(kvp.Value); success = SocketError.Success; while (key.Offset != key.Size) { int num = cl_socket.Send(key.Buffer, key.Offset, key.Size - key.Offset, SocketFlags.None, out success); if ((success != SocketError.Success) && (success != SocketError.WouldBlock)) { break; } key.Offset += num; Thread.Sleep(1); } if (success != SocketError.Success) { break; } } } #endregion Thread.Sleep(1); } } catch (Exception ex) { Console.WriteLine(ex.Message + ex.StackTrace); OnClientlessDisconnect?.Invoke(); } }
public PingConfig() { Ping = new PingStatus("OK"); DB = new DbInfo(); }
public PingStatusResult(string host, PingStatus status) { this.host = host; this.status = status; }
public async Task PersistPingInDbAsync(string id, int vehicleId, string vehicleIP, PingStatus pingStatus, DateTime pingDate) { await _vehiclePingRepository.AddPingAsync(new Models.VehiclePing() { Id = id, VehicleId = vehicleId, VehicleIP = vehicleIP, PingStatus = pingStatus, PingDate = pingDate }); }
public PingStatusResult(string host, PingStatus status, long time) { this.host = host; this.status = status; this.time = time; }
private void ProcessTraceroute(string targetNameOrAddress) { byte[] buffer = GetSendBuffer(BufferSize); if (!TryResolveNameOrAddress(targetNameOrAddress, out string resolvedTargetName, out IPAddress? targetAddress)) { if (!Quiet.IsPresent) { WriteObject(false); } return; } int currentHop = 1; PingOptions pingOptions = new PingOptions(currentHop, DontFragment.IsPresent); PingReply reply; PingReply discoveryReply; int timeout = TimeoutSeconds * 1000; Stopwatch timer = new Stopwatch(); IPAddress hopAddress; do { pingOptions.Ttl = currentHop; #if !UNIX // Get intermediate hop target. This needs to be done first, so that we can target it properly // and get useful responses. var discoveryAttempts = 0; bool addressIsValid = false; do { discoveryReply = SendCancellablePing(targetAddress, timeout, buffer, pingOptions); discoveryAttempts++; addressIsValid = !(discoveryReply.Address.Equals(IPAddress.Any) || discoveryReply.Address.Equals(IPAddress.IPv6Any)); }while (discoveryAttempts <= DefaultTraceRoutePingCount && addressIsValid); // If we aren't able to get a valid address, just re-target the final destination of the trace. hopAddress = addressIsValid ? discoveryReply.Address : targetAddress; #else // Unix Ping API returns nonsense "TimedOut" for ALL intermediate hops. No way around this // issue for traceroutes as we rely on information (intermediate addresses, etc.) that is // simply not returned to us by the API. // The only supported states on Unix seem to be Success and TimedOut. Workaround is to // keep targeting the final address; at the very least we will be able to tell the user // the required number of hops to reach the destination. hopAddress = targetAddress; discoveryReply = SendCancellablePing(targetAddress, timeout, buffer, pingOptions); #endif var hopAddressString = discoveryReply.Address.ToString(); string routerName = hopAddressString; try { if (!TryResolveNameOrAddress(hopAddressString, out routerName, out _)) { routerName = hopAddressString; } } catch { // Swallow hostname resolve exceptions and continue with traceroute } // In traceroutes we don't use 'Count' parameter. // If we change 'DefaultTraceRoutePingCount' we should change 'ConsoleTraceRouteReply' resource string. for (uint i = 1; i <= DefaultTraceRoutePingCount; i++) { try { reply = SendCancellablePing(hopAddress, timeout, buffer, pingOptions, timer); if (!Quiet.IsPresent) { var status = new PingStatus( Source, routerName, reply, reply.Status == IPStatus.Success ? reply.RoundtripTime : timer.ElapsedMilliseconds, buffer.Length, pingNum: i); WriteObject(new TraceStatus( currentHop, status, Source, resolvedTargetName, targetAddress)); } } catch (PingException ex) { string message = StringUtil.Format( TestConnectionResources.NoPingResult, resolvedTargetName, ex.Message); Exception pingException = new PingException(message, ex.InnerException); ErrorRecord errorRecord = new ErrorRecord( pingException, TestConnectionExceptionId, ErrorCategory.ResourceUnavailable, resolvedTargetName); WriteError(errorRecord); continue; } // We use short delay because it is impossible DoS with trace route. Thread.Sleep(50); timer.Reset(); } currentHop++; } while (currentHop <= MaxHops && (discoveryReply.Status == IPStatus.TtlExpired || discoveryReply.Status == IPStatus.TimedOut)); if (Quiet.IsPresent) { WriteObject(currentHop <= MaxHops); } else if (currentHop > MaxHops) { var message = StringUtil.Format( TestConnectionResources.MaxHopsExceeded, resolvedTargetName, MaxHops); var pingException = new PingException(message); WriteError(new ErrorRecord( pingException, TestConnectionExceptionId, ErrorCategory.ConnectionError, targetAddress)); } }
private void setNotification(PingStatus status) { switch (status) { case PingStatus.none: this.Icon = Properties.Resources.PM_DarkGray; notifyIcon.Icon = Properties.Resources.PM_DarkGray; this.Text = "Ping Monitor"; break; case PingStatus.good: this.Icon = Properties.Resources.PM_Green; notifyIcon.Icon = Properties.Resources.PM_Green; this.Text = "Ping Monitor | Status: good"; break; case PingStatus.poor: this.Icon = Properties.Resources.PM_Yellow; notifyIcon.Icon = Properties.Resources.PM_Yellow; this.Text = "Ping Monitor | Status: poor"; break; case PingStatus.bad: this.Icon = Properties.Resources.PM_Red; notifyIcon.Icon = Properties.Resources.PM_Red; this.Text = "Ping Monitor | Status: bad"; break; } }