public void DoPing() { try { LastPingReply = ping.Send(host, 3000); if (LastPingReply.Status == IPStatus.Success) { ErrorFromLastSucc = 0; State = ConnectionStates.Succ; } else { ErrorFromLastSucc += 1; State = ConnectionStates.Fail; } UserState = IPStatus.Success; } catch (Exception E) { ErrorFromLastSucc += 1; State = ConnectionStates.Fail; UserState = E.Message; } }
public static void DisplayReply (PingReply reply) { if (reply == null) return; Console.WriteLine ("Status: {0}", reply.Status); }
public static bool Ping(string ip) { try { if (string.IsNullOrEmpty(ip)) { return(false); } System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply reply = pingSender.Send(ip, TimeOut);//第一个参数为ip地址,第二个参数为ping的时间 if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { //ping的通 return(true); } else { //ping不通 return(false); } } catch { return(false); } }
void PingTimer_Tick(object sender, System.EventArgs e) { if (DnsNameTextBox.Text != string.Empty) { try { reply = ping.Send("HIGHVOLTAGE", 100); if (reply.Status == IPStatus.Success) { IsWorking = true; TrayIcon.Icon = SimpleServController.Properties.Resources.ServCotrolEnabled; SwitchOnMenuItem.Text = "Выключить"; } else { IsWorking = false; TrayIcon.Icon = SimpleServController.Properties.Resources.ServCotrolDisabled; SwitchOnMenuItem.Text = "Включить"; } } catch (System.Net.NetworkInformation.PingException ex) { IsWorking = false; TrayIcon.Icon = SimpleServController.Properties.Resources.ServCotrolDisabled; SwitchOnMenuItem.Text = "Включить"; } } }
public static bool CheckServerConnectivity(string ipAddress) { bool connectionExists = false; string status = ""; try { System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions(); options.DontFragment = true; if (!string.IsNullOrEmpty(ipAddress)) { System.Net.NetworkInformation.PingReply reply = pingSender.Send(ipAddress); connectionExists = reply.Status == System.Net.NetworkInformation.IPStatus.Success ? true : false; } } catch (PingException ex) { status = ex.Message.ToString(); } catch (AggregateException ex) { foreach (Exception inner in ex.InnerExceptions) { status = inner.Message.ToString(); } } return(connectionExists); }
public static bool PingTest(string aIPAddr) { System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply reply = p.Send(aIPAddr); return(reply.Status.Equals(IPStatus.Success) ? true : false); }
private String pingIps(String firstBit, String myAddr) { String curIp; for (int i = 1; i <= 255; i++) { output.text = i + ""; Debug.Log("Go " + DateTime.Now.ToString("HH:mm:ss tt")); curIp = firstBit + "." + i; try { System.Net.NetworkInformation.PingReply rep = p.Send(curIp, 100); output.text = "pinged " + i; if (rep.Status == System.Net.NetworkInformation.IPStatus.Success && curIp != myAddr) { return(curIp); //host is active } } catch (Exception e) { output.text = e + ""; } } return(""); }
/// <summary> /// 检测IP /// </summary> /// <param name>strIP</param> /// <returns></returns> public static bool PingIP(string strIP, ref long pingReplyRoundtripTime) { try { if (!IsValidIP(strIP)) { return(false); } System.Net.NetworkInformation.Ping psender = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply prep = psender.Send(strIP, 500, Encoding.Default.GetBytes("welcome_use_this_soft_write_by_airotop")); if (prep.Status == System.Net.NetworkInformation.IPStatus.Success) { pingReplyRoundtripTime = prep.RoundtripTime; return(true); } return(false); } catch (Exception ex) { // MessageBox.Show(ex.Message); string date_str = DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(); ClassLog.Writelog(date_str, " ServrerMonitor_PingIP ", ex.Message); return(false); } }
/// <summary> /// Performs a pathping /// </summary> /// <param name="ipaTarget">The target</param> /// <param name="iHopcount">The maximum hopcount</param> /// <param name="iTimeout">The timeout for each ping</param> /// <returns>An array of PingReplys for the whole path</returns> public static PingReply[] PerformPathping(IPAddress ipaTarget, int iHopcount, int iTimeout) { System.Collections.ArrayList arlPingReply = new System.Collections.ArrayList(); Ping myPing = new Ping(); PingReply prResult = null; int iTimeOutCnt = 0; for (int iC1 = 1; iC1 < iHopcount && iTimeOutCnt<5; iC1++) { prResult = myPing.Send(ipaTarget, iTimeout, new byte[10], new PingOptions(iC1, false)); if (prResult.Status == IPStatus.Success) { iC1 = iHopcount; iTimeOutCnt = 0; } else if (prResult.Status == IPStatus.TtlExpired) { iTimeOutCnt = 0; } else if (prResult.Status == IPStatus.TimedOut) { iTimeOutCnt++; } arlPingReply.Add(prResult); } PingReply[] prReturnValue = new PingReply[arlPingReply.Count]; for (int iC1 = 0; iC1 < arlPingReply.Count; iC1++) { prReturnValue[iC1] = (PingReply)arlPingReply[iC1]; } return prReturnValue; }
private void Sniffer_PingReceived(IPAddress address, System.Net.NetworkInformation.PingReply reply) { // Write to Logs string msg = "Ping Received : " + address.ToString() + " : " + reply.Status + " in " + reply.RoundtripTime + "ms"; Log(msg); log.Info(msg); }
/// <summary> /// This function will deal with delays of setting up an agent. /// </summary> /// <returns>IEnumerator to allow for delays.</returns> public IEnumerator SlowAgentStart() { bool UsePublic = false; bool UseFlorida = false; //Ping Public Ip address to see if we are external.......... //GenericNetworkCore.Logger("Trying Public IP Address: " + PublicIP.ToString()); System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingOptions po = new System.Net.NetworkInformation.PingOptions(); po.DontFragment = true; string data = "HELLLLOOOOO!"; byte[] buffer = ASCIIEncoding.ASCII.GetBytes(data); int timeout = 500; System.Net.NetworkInformation.PingReply pr = ping.Send(PublicIP, timeout, buffer, po); yield return(new WaitForSeconds(1.5f)); Debug.Log("Ping Return: " + pr.Status.ToString()); if (pr.Status == System.Net.NetworkInformation.IPStatus.Success) { GenericNetworkCore.Logger("The public IP responded with a roundtrip time of: " + pr.RoundtripTime); UsePublic = true; IP = PublicIP; } else { GenericNetworkCore.Logger("The public IP failed to respond"); UsePublic = false; } //-------------------If not public, ping Florida Poly for internal access. if (!UsePublic) { GenericNetworkCore.Logger("Trying Florida Poly Address: " + FloridaPolyIP.ToString()); pr = ping.Send(FloridaPolyIP, timeout, buffer, po); yield return(new WaitForSeconds(1.5f)); Debug.Log("Ping Return: " + pr.Status.ToString()); if (pr.Status.ToString() == "Success") { GenericNetworkCore.Logger("The Florida Poly IP responded with a roundtrip time of: " + pr.RoundtripTime); UseFlorida = true; IP = FloridaPolyIP; } else { GenericNetworkCore.Logger("The Florida Poly IP failed to respond"); UseFlorida = false; } } //Otherwise use local host, assume testing. if (!UsePublic && !UseFlorida) { IP = "127.0.0.1"; GenericNetworkCore.Logger("Using Home Address!"); } this.StartAgent(); }
public PN() { System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingReply = ping.Send("192.168.9.200"); //адрес куда надо отправить Console.WriteLine(pingReply.RoundtripTime); //время ответа Console.WriteLine(pingReply.Status); //статус Console.WriteLine(pingReply.Address); //IP // Console.ReadKey(true); }
internal NetworkDictionaryItem( IPAddress ipAddress, PingReply pingReply, PhysicalAddress macAddress, IPHostEntry hostEntry, IOS os ) { _ipAddress = ipAddress; _pingReply = pingReply; _macAddress = macAddress; _hostEntry = hostEntry; _os = os; _ports = new ConcurrentDictionary<ushort,ushort>(); }
public void TestConnection() { _reply = _pinger.Send (_hostname, _timeout, _buffer, _pingerOptions); Assert.AreNotEqual (_reply.Status, IPStatus.TimedOut); Assert.AreNotEqual ( _reply.Status, IPStatus.TtlExpired); Assert.AreNotEqual (_reply.Status, IPStatus.DestinationUnreachable); Assert.AreEqual (_reply.Status, IPStatus.Success); }
internal PingHostInfo(PingTaskBase task, IPAddress address, PingReply reply, Exception error, int bufferSize) { _host = task.HostName; _hostAndAddress = task.HostNameWithAddress(address); _reply = reply; _error = error; _address = address; _bufferSize = bufferSize; }
public static bool IsConnectedToDomain(string host) { System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply rep = p.Send(host); if (rep.Status == System.Net.NetworkInformation.IPStatus.Success) { return(true); } return(false); }
// Constructor public TraceRtNode(PingReply ping, IPHostEntry host) { hostaddr = ping.Address; status = ping.Status; if(host != null) hostname = host.HostName; else hostname = ""; roundtriptime = (int)ping.RoundtripTime; }
private bool ping() { System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply reply = pingSender.Send("http://www.google.com"); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { return(true); } else { return(false); } }
//to check for internet connection, we ping google's website using their IP. If the website returns success then, it returns true that internet connection exists. public static bool InternetConnectionExists() { System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingStatus = ping.Send(System.Net.IPAddress.Parse("208.69.34.231"), 5000); if (pingStatus.Status == System.Net.NetworkInformation.IPStatus.Success) { return(true); } else { return(false); } }
public static void DisplayReply(PingReply reply) { if (reply == null) return; //Console.WriteLine("ping status: {0}", reply.Status); if (reply.Status == IPStatus.Success) { //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); } }
public bool PingTest(string strURL) { System.Net.NetworkInformation.Ping objPing = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingOptions objOptions = new System.Net.NetworkInformation.PingOptions(); objOptions.DontFragment = true; try{ System.Net.NetworkInformation.PingReply objReply = objPing.Send(strURL, 4); return(true); } catch (SystemException e) { return(false); } }
public void AddOrUpdate( IPAddress ipAddress, PingReply pingReply ) { if( ipAddress == null ) throw new ArgumentNullException( "ipAddress" ); if( pingReply == null ) throw new ArgumentNullException( "pingReply" ); if( _networkDictionaryItems.ContainsKey( ipAddress ) ) { INetworkDictionaryItem networkDictionaryItem = _networkDictionaryItems[ipAddress]; networkDictionaryItem.Update( new NetworkDictionaryItem( pingReply ) ); _isModified = _networkDictionaryItems.TryUpdate( ipAddress, networkDictionaryItem, networkDictionaryItem ); } else { _isModified = _networkDictionaryItems.TryAdd( ipAddress, new NetworkDictionaryItem( pingReply ) ); } }
private static PingReply DoPing(string AddressToPing) { //we dont really care about the data string data = "This is a ping test"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 1024; System.Net.NetworkInformation.Ping sendPing = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions { DontFragment = true }; System.Net.NetworkInformation.PingReply reply = sendPing.Send(AddressToPing, timeout, buffer, options); return(reply); }
private void Button5_Click(object sender, EventArgs e) { System.Net.NetworkInformation.Ping png = new Ping(); System.Net.NetworkInformation.PingReply pingReply = png.Send("tdupz.ru"); if (pingReply.Status == IPStatus.Success) { MessageBox.Show("Соединение утсановлено... Перезапустите 1С и повторите попытку"); } else { MessageBox.Show("Имеются проблемы со связью. Перезагрузите компьютер.После запуска 1с миунт через 15-20 повторите попытку. "); } // MessageBox.Show("Перезагрузите компьютер и после запуска 1с миунт через 15-20 повторите попытку."); }
/// <summary> /// Function For Ping Request Alive OR Not /// </summary> public static string NetPingRequest(string IP) { string result = "ERROR"; try { System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply reply = ping.Send(IP); bool req = reply.Status == System.Net.NetworkInformation.IPStatus.Success; result = string.Format("Response: {0}, Estimate: {1} ms", req, reply.RoundtripTime); } catch (Exception x) { Debug.WriteLine(x.Message); Debug.WriteLine(x.StackTrace); } return(result); }
private string GetPingMessage(PingReply reply) { string error = ""; string timoutError = reply.Status != IPStatus.Success ? string.Format("The timout Time period of {0} has been exceeded", pingTimeout) : string.Format("Roundtrip time {0} ", reply.RoundtripTime.ToString()); string roundTripError = reply.RoundtripTime > 3000 ? string.Format("The roundtrip time period of {0} has been exceeded", roundTripTime * 60) : string.Format("Roundtrip time{0} ", reply.RoundtripTime.ToString()); if (reply.Status != IPStatus.Success ) error = timoutError; if (reply.RoundtripTime > roundTripTime) error = roundTripError; return error; }
private void primaryTick(Object myObject, EventArgs myEventArgs) { if (primaryPingRunning == true) { try { replyPrimaryTarget = pingTarget.Send(primaryTargetIP); setReplyOutput(ref primaryReply_txt, replyPrimaryTarget); if (replyPrimaryTarget.Status != IPStatus.Success) replyPrimaryTarget = null; } catch { replyPrimaryTarget = null; primaryReply_txt.Text = "Some error has occurred."; } } else replyPrimaryTarget = null; if (secondaryPingRunning == true) { try { replySecondaryTarget = pingTarget.Send(secondaryTargetIP); setReplyOutput(ref secondaryReply_txt, replySecondaryTarget); if (replySecondaryTarget.Status != IPStatus.Success) replySecondaryTarget = null; } catch { replySecondaryTarget = null; secondaryReply_txt.Text = "Some error has occurred."; } } else replySecondaryTarget = null; checkReply(replyPrimaryTarget, replySecondaryTarget); }
/// <summary> /// Ping某个IP地址 /// </summary> /// <param name="ip">IP地址</param> /// <returns>成功Success失败TimeOut</returns> public static string PingResult(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 = "landi"; //byte[] buffer = Encoding.ASCII.GetBytes(data); //int timeout = 5000; System.Net.NetworkInformation.PingReply reply = p.Send(ip);//, timeout, buffer, options); return(reply.Status.ToString()); } catch (System.Exception e) { Log.Error("[PubFunc.cs][PingResult]Error!\n" + e.ToString()); return("fail"); } }
public static bool Ping(string hostNameOrAddress, int timeout, out Exception error) { var success = false; error = null; var sw = new System.Diagnostics.Stopwatch(); sw.Start(); System.Net.NetworkInformation.PingReply reply = null; Exception replyError = null; // Use proper threading, because other asynchronous classes // like "Tasks" have problems with Ping. var ts = new System.Threading.ThreadStart(delegate() { var ping = new System.Net.NetworkInformation.Ping(); try { reply = ping.Send(hostNameOrAddress); } catch (Exception ex) { replyError = ex; } ping.Dispose(); }); var t = new System.Threading.Thread(ts); t.Start(); t.Join(timeout); if (reply != null) { success = (reply.Status == System.Net.NetworkInformation.IPStatus.Success); } else if (replyError != null) { error = replyError; } else { error = new Exception("Ping timed out (" + timeout.ToString() + "): " + sw.Elapsed.ToString()); } return(success); }
public static bool Ping(string IP) { //string content = RunCmd("Ping.exe", IP); //bool isPinged = TextHelper.IsContains(content, "TTL=", "MS", "Reply"); //return isPinged; using (NI.Ping ping = new NI.Ping()) { try { NI.PingReply pr = ping.Send(IP); return(pr.Status == NI.IPStatus.Success); } catch (System.Exception ex) { Trace.WriteLine(ex.Message); return(false); } } }
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); } }
public bool send(string ipAddrOrHost) { // Create a buffer of 32 bytes of data to be transmitted. string data = "abcdefghijklmnopqrstuvwxyz"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 120; if (ipAddrOrHost == null || ipAddrOrHost == "") ipAddrOrHost = "10.0.0.4"; reply = pingSender.Send(ipAddrOrHost, timeout, buffer, options); if (reply.Status == IPStatus.Success) { Console.WriteLine("Address: {0}", reply.Address.ToString()); Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime); Console.WriteLine("Buffer size: {0}", reply.Buffer.Length); return true; } else { return false; } }
private void DisplayReply(PingReply reply) { if (reply == null) return; StringBuilder replyBuilder = new StringBuilder(); replyBuilder.AppendFormat(" Reply status ...... : {0}\n", GetStatusString(reply.Status)); if (reply.Status == IPStatus.Success) { replyBuilder.AppendFormat(" Reply from ........ : {0}\n", reply.Address.ToString()); replyBuilder.AppendFormat(" Bytes (buffer size) : {0}\n", reply.Buffer.Length); replyBuilder.AppendFormat(" Roundtrip time .... : {0} ms\n", reply.RoundtripTime); replyBuilder.AppendFormat(" Time to live (TTL) : {0}\n", reply.Options.Ttl); replyBuilder.AppendFormat(" Don't fragment .... : {0}\n", reply.Options.DontFragment); } richTextBoxResult.Text = replyBuilder.ToString(); }
public static void DisplayReply(PingReply reply, string address) { if (reply == null) return; if (reply.Status == IPStatus.Success) { Log(String.Format("Reply from {0} with resonse time {1}", reply.Address.ToString(), reply.RoundtripTime.ToString() )); } else { string add = address; string stat = reply.Status.ToString(); string fail = String.Format("Failed Response to {0} - {1}", add, stat); Log(fail, true); } }
public static bool PingIP(string IP) { bool result = false; try { Ping ping = new Ping(); System.Net.NetworkInformation.PingReply pingReply = ping.Send(IP); if (pingReply.Status == System.Net.NetworkInformation.IPStatus.Success) { result = true; } } catch { result = false; } return(result); }
public void SendAll() { var ping = new Net.Ping(); var replies = new Net.PingReply[interfaces.Count]; var errors = new Net.PingException[interfaces.Count]; for (var i = 0; i < interfaces.Count; i++) { var ip = interfaces[i]; try { replies[i] = ping.Send(ip.Address); } catch (Net.PingException e) { errors[i] = e; } } UpdateConsole(replies); }
static public bool CheckNetworkStatus(string ip) { bool networkFlag = false; Ping p = new Ping(); PingOptions pOption = new PingOptions(); pOption.DontFragment = true; string data = "Test Data!"; byte[] buffer = Encoding.ASCII.GetBytes(data); int timeout = 500; // Timeout System.Net.NetworkInformation.PingReply reply = p.Send(ip, timeout, buffer, pOption); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { networkFlag = true; } return(networkFlag); }
private static void pingThread() { while (true) { try { foreach (virtualUser User in _Users) { if (User.pingOK) { try { byte[] buffer = new byte[32]; System.Net.NetworkInformation.PingOptions pingOptions = new System.Net.NetworkInformation.PingOptions(128, true); System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingReply = ping.Send(((IPEndPoint)User.uSocket.RemoteEndPoint).Address, 75, buffer, pingOptions); if (pingReply != null) { switch (pingReply.Status) { case System.Net.NetworkInformation.IPStatus.Success: User.Ping = pingReply.RoundtripTime; break; } } } catch { } User.pingOK = false; User.send(new PACKET_PING(User)); } } } catch { } Thread.Sleep(2500); } }
/// <summary> /// Performs a trace route on an ip address /// </summary> /// /// <param name="Address">The target ip address</param> /// <param name="MaxHops">The maximum hopcount</param> /// <param name="PingTimeout">The timeout for each ping</param> /// /// <returns>An array of PingReplys for the whole path</returns> public static PingReply[] TraceRoute(IPAddress Address, int MaxHops, int PingTimeout) { ArrayList replies = new ArrayList(); Ping echo = new Ping(); PingReply reply; for (int i = 1; i < MaxHops; i++) { reply = echo.Send(Address, PingTimeout, new byte[10], new PingOptions(i, false)); if (reply.Status == IPStatus.Success) i = MaxHops; replies.Add(reply); } PingReply[] pingReplies = new PingReply[replies.Count]; for (int i = 0; i < replies.Count; i++) pingReplies[i] = (PingReply)replies[i]; return pingReplies; }
/// <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); } }
private string ParseResponse(PingReply hostname, string device) { string returnMsg = ""; try { // If the ping reply isn't null... if (hostname != null) { // based on our connection status, return a message switch (hostname.Status) { case IPStatus.Success: returnMsg = $"Reply from {device} with address {hostname.Address}"; break; case IPStatus.TimedOut: returnMsg = "Connection has timed out."; break; default: returnMsg = $"Ping to {device} failed with message {NetworkServices.GetIpStatusMessage(hostname.Status)}"; break; } } else { returnMsg = "Connection failed for an unknown reason. Likely, the host name is not known."; } } catch (PingException ex) { returnMsg = $"Connection Error: {ex.Message}"; } catch (SocketException ex) { returnMsg = $"Connection Error: {ex.Message}"; } return returnMsg; }
public static bool PingTest() { try { System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply pingStatus = ping.Send(IPAddress.Parse("208.69.34.231"), 1000);//208.69.34.231 means google .com if (pingStatus.Status == System.Net.NetworkInformation.IPStatus.Success) { return(true); } else { return(false); } } catch (Exception) { return(false); } }
public void passArgsData(PingReply reply) { string[] data = new string[2]{reply.Address.ToString(),reply.RoundtripTime.ToString()}; setDataList(data); }
public void PingResult(ServerInfo infoServer, PingReply reply) { Int64 result = 0; if (reply.Status == IPStatus.Success) { result = reply.RoundtripTime; } else { result = -1; } PingResult(infoServer, result); }
public static bool IsAlive(string ip) { System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply rep = p.Send(ip); return(rep.Status == System.Net.NetworkInformation.IPStatus.Success); }
/// <summary> /// Performs a pathping /// </summary> /// <param name="ipaTarget">The target</param> /// <param name="iHopcount">The maximum hopcount</param> /// <param name="iTimeout">The timeout for each ping</param> /// <returns>An array of PingReplys for the whole path</returns> public PingReply[] PerformPathping(IPAddress ipaTarget, int iHopcount = 20, int iTimeout = 500) { System.Collections.ArrayList arlPingReply = new System.Collections.ArrayList(); Ping myPing = new Ping(); PingReply prResult; for (int iC1 = 1; iC1 < iHopcount; iC1++) { try { prResult = myPing.Send(ipaTarget, iTimeout, new byte[10], new PingOptions(iC1, false)); //ttl zwiekszany } catch (PingException e) { return null; } if (prResult.Status == IPStatus.Success) //osiagnieto hosta przy danym ttl { iC1 = iHopcount; // sprawdzic czy nie wystarcyz po prostu dac breaka } arlPingReply.Add(prResult); Console.WriteLine(((PingReply)prResult).Address); } PingReply[] prReturnValue = new PingReply[arlPingReply.Count]; for (int iC1 = 0; iC1 < arlPingReply.Count; iC1++) { prReturnValue[iC1] = (PingReply)arlPingReply[iC1]; } return prReturnValue; }
private Action ProcessPingReply(PingReply lReply, Exception exception) { return new Action( delegate() { if (lReply == null) { Results.Items.Add(String.Format("{0}\n", exception.Message)); lRunPing = false; Start.Content = "Start"; HostName.IsEnabled = true; Timeout.IsEnabled = true; return; } ((PingHost)HostName.SelectedItem).PingReplies.Add(new PingHostReply() { HostPingReply = lReply, ResponseTimestamp = DateTime.Now }); StringBuilder lSB = new StringBuilder(); if (lReply.Status == IPStatus.Success) { lSB.AppendLine(String.Format("{0} - Result: {1}, RoundTrip Time: {2}", DateTime.Now.ToLongTimeString(), lReply.Status, lReply.RoundtripTime)); TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Normal; double lPercent = lReply.RoundtripTime / (double)PingTimeout; TaskbarItemInfo.ProgressValue = lPercent; progressBar1.Value = lReply.RoundtripTime; } else { lSB.AppendLine(String.Format("{0} - Result: {1}, RoundTrip Time: {2}", DateTime.Now.ToLongTimeString(), lReply.Status, lReply.RoundtripTime)); TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error; TaskbarItemInfo.ProgressValue = 0; progressBar1.Value = 0; } Results.Items.Add(lSB.ToString()); if (Results.Items.Count > 10) { Results.Items.RemoveAt(0); } } ); }
public bool Update( INetworkDictionaryItem networkDictionaryItem ) { //peut etre une methode plus mieu if( networkDictionaryItem.Host != null ) _host = networkDictionaryItem.Host; if( networkDictionaryItem.HostEntity != null ) _hostEntity = networkDictionaryItem.HostEntity; if( networkDictionaryItem.PingReply != null ) _pingReply = networkDictionaryItem.PingReply; if( networkDictionaryItem.IPAddress != null ) _ipAddress = networkDictionaryItem.IPAddress; if( networkDictionaryItem.MacAddress != null ) _macAddress = networkDictionaryItem.MacAddress; if( networkDictionaryItem.HostEntry != null ) _hostEntry = networkDictionaryItem.HostEntry; if( networkDictionaryItem.OS != null ) _os = networkDictionaryItem.OS; return true; //FAIL }
private void timer1_Tick(object sender, EventArgs e) { pr = pinger.Send("google.com"); lb_Status.Text = "Google response time: " + pr.RoundtripTime + " ms"; }
internal PingCompletedEventArgs (Exception ex, bool cancelled, object userState, PingReply reply) : base (ex, cancelled, userState) { this.reply = reply; }
public long Ping() { System.Net.NetworkInformation.Ping tempPing = new System.Net.NetworkInformation.Ping(); System.Net.NetworkInformation.PingReply temPingReply = tempPing.Send(m_ipAddr); return(temPingReply.RoundtripTime); }
internal PingCompletedEventArgs(Exception ex, bool cancelled, object userState, PingReply reply) : base(ex, cancelled, userState) { this.reply = reply; }
/// <summary> /// 转换为字符串格式 /// </summary> /// <param name="value"></param> /// <returns></returns> public static String ToContentString(this PingReply value) { return(String.Format("{0} bytes from {1} reply: Time={2}ms TTL={3} Status={4}", value.Buffer.Length, value.Address.ToString(), value.RoundtripTime, value.Options.Ttl, value.Status)); }
public PingResult(PingReply wrapped) { _wraped = wrapped; this.TimeStamp = DateTime.Now; }
public void Ping() { var pinger = new System.Net.NetworkInformation.Ping(); try { Reply = pinger.Send(Server); Logger.Debug( string.Format("Ping test to {0} was {1} and roundtrip was {2}", Server, Reply.Status, Reply.RoundtripTime), typeof (ServerPinger)); } catch (Exception ex_) { Reply = null; Logger.Error(string.Format("Error pinging {0}", Server), typeof (ServerPinger), ex_); } }
public PingReplyReceivedEventArgs(PingReply reply) { PingReply = reply; }
internal NetworkDictionaryItem(PingReply pingReply) : this(pingReply.Address, pingReply, null, null, null) { }
/// <summary> /// Updates the current status for the corresponding device from which response is received /// </summary> /// <param name="reply"></param> public static void UpdateDeviceCurrentStatus(PingReply reply) { if (reply != null && reply.Address.ToString() != "") { Device device = DeviceList.getDevice(reply.Address); if (device != null) { device.CurrentStatus = (reply.Status == IPStatus.Success) ? NetworkStatus.ONLINE : NetworkStatus.OFFLINE; device.lastUpdateTime = DateTime.Now; DeviceList.editDevice(device); } } }
public PingStatus ResolveReplyType( PingReply pingReplier ) { return new PingStatus( pingReplier ); }
private bool TryGetPingReply(SocketConfig socketConfig, byte[] receiveBuffer, int bytesReceived, Stopwatch sw, ref int ipHeaderLength, out PingReply reply) { byte type, code; reply = null; if (socketConfig.IsIpv4) { // Determine actual size of IP header byte ihl = (byte)(receiveBuffer[0] & 0x0f); // Internet Header Length ipHeaderLength = 4 * ihl; if (bytesReceived - ipHeaderLength < IcmpHeaderLengthInBytes) { return(false); // Not enough bytes to reconstruct actual IP header + ICMP header. } } int icmpHeaderOffset = ipHeaderLength; // Skip IP header. IcmpHeader receivedHeader = MemoryMarshal.Read <IcmpHeader>(receiveBuffer.AsSpan(icmpHeaderOffset)); type = receivedHeader.Type; code = receivedHeader.Code; if (socketConfig.Identifier != receivedHeader.Identifier || type == (byte)IcmpV4MessageType.EchoRequest || type == (byte)IcmpV6MessageType.EchoRequest) // Echo Request, ignore { return(false); } sw.Stop(); long roundTripTime = sw.ElapsedMilliseconds; int dataOffset = ipHeaderLength + IcmpHeaderLengthInBytes; // We want to return a buffer with the actual data we sent out, not including the header data. byte[] dataBuffer = new byte[bytesReceived - dataOffset]; Buffer.BlockCopy(receiveBuffer, dataOffset, dataBuffer, 0, dataBuffer.Length); IPStatus status = socketConfig.IsIpv4 ? IcmpV4MessageConstants.MapV4TypeToIPStatus(type, code) : IcmpV6MessageConstants.MapV6TypeToIPStatus(type, code); IPAddress address = ((IPEndPoint)socketConfig.EndPoint).Address; reply = new PingReply(address, socketConfig.Options, status, roundTripTime, dataBuffer); return(true); }