XWidgetSoft Forum https://bbs.xwidget.com/ |
|
Ping to server https://bbs.xwidget.com/viewtopic.php?f=8&t=2543 |
Page 1 of 1 |
Author: | dimmas375 [ January 28th, 2013, 3:11 pm ] |
Post subject: | Ping to server |
Hi everybody Is there any possibility to implement a ping to specific server feature to determine whether it is online and time of their response? Thank you in advance |
Author: | digigamer [ April 28th, 2013, 7:05 pm ] |
Post subject: | Re: Ping to server |
you can use WMI to do that... here is some jscript code: Code: //good practice to reuse com components var wmi = GetObject("Winmgmts:"); function Ping(host) { var eStatus = new Enumerator(wmi.ExecQuery("Select StatusCode from Win32_PingStatus Where Address='" + host + "'")); if(eStatus.item().StatusCode == 0) { //host reachable //response time var response = eStatus.item().ResponseTime; //do something... } else { //ping failed... server not available } } ![]() Here is more reference on pinging http://msdn.microsoft.com/en-us/library/windows/desktop/aa394350(v=vs.85).aspx |
Author: | dimmas375 [ April 29th, 2013, 1:00 am ] |
Post subject: | Re: Ping to server |
Thank you. I've never used WMI before. Only one thing. Here: Quote: var eStatus = new Enumerator(wmi.ExecQuery("Select StatusCode from Win32_PingStatus Where Address='" + host + "'")); must be '*' instead of 'StatusCode', or ResponseTime will be undefined all time. |
Author: | digigamer [ April 29th, 2013, 4:36 pm ] |
Post subject: | Re: Ping to server |
Oh! Sorry... my wrong. I never saw that... I first thought u wanted status code only |
Page 1 of 1 | All times are UTC - 8 hours |
Powered by phpBB® Forum Software © phpBB Group http://www.phpbb.com/ |