/// <summary> /// Pings the given address once. /// </summary> /// <param name="Address"></param> /// <param name="timeout"></param> /// <returns></returns> public static PingTypes Ping(IPAddress Address, int timeout = 2500) { var pinger = new Ping(); var pingTypes = new PingTypes(); try { PingReply reply = pinger.Send(Address, timeout); pingTypes.Time = reply.RoundtripTime; pingTypes.buffer = reply.Buffer; pingTypes.IPstatus = reply.Status; pingTypes.pingable = reply.Status == IPStatus.Success; } catch (PingException) { } // Discard PingExceptions and return false; finally { if (pinger != null) { pinger.Dispose(); } } //return pingable; return(pingTypes); }
public SaveData(List <EntryData> entryData, PingTypes pingType, bool visualMode, bool autoClose, bool showFullPath, bool showFullPathForFolders) { EntryData = entryData; PingType = pingType; VisualMode = visualMode; AutoClose = autoClose; ShowFullPath = showFullPath; ShowFullPathForFolders = showFullPathForFolders; }
public static Task <PingResult> SendAsync(IPAddress address, int port, PingTypes pingType, int timeout = 5000) { if (pingType == PingTypes.Icmp) { return(SendIcmpAsync(address, timeout)); } else if (pingType == PingTypes.Udp) { return(SendUdpAsync(address, port, timeout)); } return(null); }
public GameObject SpawnPing(PingTypes pingType, Vector3 spawnPosition) { GameObject newPing; Debug.Log(pingType); Debug.Log(Pings); switch (pingType) { case PingTypes.Door: newPing = Instantiate(Pings[1]); newPing.transform.position = spawnPosition; break; case PingTypes.Teleport: newPing = Instantiate(Pings[2]); newPing.transform.position = spawnPosition; break; case PingTypes.Hacking: newPing = Instantiate(Pings[3]); newPing.transform.position = spawnPosition; break; case PingTypes.Jailed: newPing = Instantiate(Pings[4]); newPing.transform.position = spawnPosition; break; case PingTypes.Help: newPing = Instantiate(Pings[5]); newPing.transform.position = spawnPosition; break; case PingTypes.UnJail: newPing = Instantiate(Pings[6]); newPing.transform.position = spawnPosition; break; default: newPing = Instantiate(Pings[0]); newPing.transform.position = spawnPosition; break; } newPing.transform.localScale *= 3.0f; return(newPing); }
/// <summary> /// Archives an array of pings to the given address. /// </summary> /// <param name="Address"></param> /// <param name="timeout"></param> /// <param name="times"></param> /// <returns></returns> public static PingTypes[] Pings(string Address, ushort times = 2, int timeout = 2500) { if (times > 0) { var pings = new PingTypes[times]; for (int i = 0; i < times; i++) { pings[i] = Ping(Address, timeout); } return(pings); } else { return(null); } }
private void LoadSettings() { //attempt to load the entries _currentSettings = IOHelper.ReadFromDisk <SaveData>(SETTINGS_FILENAME); //if nothing is saved, retrieve the default values if (_currentSettings == null) { _currentSettings = new SaveData(); _currentSettings.PingType = PingTypes.Both; _currentSettings.Save(); } _tempLocations.AddRange(EntryData.Clone(_currentSettings.EntryData.ToArray())); _pingType = _currentSettings.PingType; _visualMode = _currentSettings.VisualMode; VisualMode(_visualMode); _autoClose = _currentSettings.AutoClose; _showFullPath = _currentSettings.ShowFullPath; _showFullPathForFolder = _currentSettings.ShowFullPathForFolders; }
private void DrawInnerSettings() { EditorGUILayout.BeginVertical(_boxStyle); EditorGUILayout.LabelField("General Settings", _boldLabelStyle); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.BeginHorizontal(); string label = "Current Ping Type : "; EditorGUILayout.LabelField(label, GUILayout.MaxWidth(label.Length * 7.3f)); if (_pingType == PingTypes.Ping) { if (GUILayout.Button("Ping", _buttonStyle, GUILayout.ExpandWidth(false))) { _pingType = PingTypes.Selection; _currentSettings.PingType = _pingType; _currentSettings.Save(); } } else if (_pingType == PingTypes.Selection) { if (GUILayout.Button("Selection", _buttonStyle, GUILayout.ExpandWidth(false))) { _pingType = PingTypes.Both; _currentSettings.PingType = _pingType; _currentSettings.Save(); } } else if (_pingType == PingTypes.Both) { if (GUILayout.Button("Both", _buttonStyle, GUILayout.ExpandWidth(false))) { _pingType = PingTypes.Ping; _currentSettings.PingType = _pingType; _currentSettings.Save(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); _controlAutoClose = _autoClose; _autoClose = EditorGUILayout.Toggle("Auto Close : ", _autoClose); if (_controlAutoClose != _autoClose) { _autoCloseChanged = true; } if (_autoCloseChanged) { _currentSettings.AutoClose = _autoClose; _currentSettings.Save(); _autoCloseChanged = false; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); label = "Show Full Path : "; _controlShowFullPath = _showFullPath; _showFullPath = EditorGUILayout.Toggle(label, _showFullPath); if (_controlShowFullPath != _showFullPath) { _showFullPathChanged = true; } if (_showFullPathChanged) { _currentSettings.ShowFullPath = _showFullPath; _currentSettings.Save(); _showFullPathChanged = false; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); label = "Show Full Path(Folders) : "; _controlShowFullPathForFolder = _showFullPathForFolder; _showFullPathForFolder = EditorGUILayout.Toggle(label, _showFullPathForFolder); if (_controlShowFullPathForFolder != _showFullPathForFolder) { _showFullPathForFolderChanged = true; } if (_showFullPathForFolderChanged) { _currentSettings.ShowFullPathForFolders = _showFullPathForFolder; _currentSettings.Save(); _showFullPathForFolderChanged = false; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); label = "Visual Mode(Experimental!) : "; _controlVisualMode = _visualMode; _visualMode = EditorGUILayout.Toggle(label, _visualMode); if (_controlVisualMode != _visualMode) { _visualModeChanged = true; } if (_visualModeChanged) { VisualMode(_visualMode); _currentSettings.VisualMode = _visualMode; _currentSettings.Save(); _visualModeChanged = false; } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }
public static PingUnitResult GetResult(IPAddress address, IEnumerable <PingResult> results, PingTypes pingType) { PingUnitResult result = new PingUnitResult() { Address = address, PingType = pingType, }; if (results == null || !results.Any()) { result.LostPercent = 1; return(result); } var successes = results.Where(m => m != null && m.Status == IPStatus.Success); result.SentCount = results.Count(); result.ReceivedCount = successes.Count(); result.LostPercent = (float)(result.SentCount - result.ReceivedCount) / (float)result.SentCount; if (successes != null && successes.Any()) { var ascResults = successes.OrderBy(m => m.RoundtripTime); var minItem = ascResults.FirstOrDefault(); var maxItem = ascResults.LastOrDefault(); result.MinRoundtripTime = minItem.RoundtripTime; result.MaxRoundtripTime = maxItem.RoundtripTime; result.AverageRoundtripTime = successes.Average(m => m.RoundtripTime); } return(result); }