{"id":153,"date":"2013-09-15T08:18:40","date_gmt":"2013-09-15T15:18:40","guid":{"rendered":"http:\/\/www.coretechnologies.com\/blog\/?p=153"},"modified":"2026-02-08T22:01:52","modified_gmt":"2026-02-09T06:01:52","slug":"http-ping-6-0-returns-http-status-code","status":"publish","type":"post","link":"https:\/\/www.coretechnologies.com\/blog\/http-ping\/http-ping-6-0-returns-http-status-code\/","title":{"rendered":"Hey scripters, http-ping now returns the HTTP status code"},"content":{"rendered":"<p>\nSavvy programmers and administrators often use our free <a href=\"\/products\/http-ping\/\">http-ping<\/a> command line utility to check that their web servers up and serving pages. http-ping&#8217;s return code (the percentage of page downloads that succeeded) lets them know when the web server is not responding, enabling them to take the appropriate action (for example sending an email or rebooting the server). This works very well when a web server fails to respond but it can&#8217;t detect more subtle problems, such as when the server is responding but returning an error.\n<\/p>\n<p>\nhttp-ping version 6.0 addresses that problem. By returning the <a href=\"http:\/\/en.wikipedia.org\/wiki\/List_of_HTTP_status_codes\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">HTTP status code<\/a> from the server&#8217;s response, a script can detect <a href=\"http:\/\/en.wikipedia.org\/wiki\/HTTP_404\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">404&#8217;s (Not Found)<\/a>, 500&#8217;s (Internal Server Error) or any other non-standard replies.\n<\/p>\n<p>\nUsers of <a href=\"\/products\/AlwaysUp\/\">AlwaysUp<\/a> (and <a href=\"\/products\/ServiceProtector\/\">Service Protector<\/a>) can deploy http-ping to detect failures and restart their web servers when necessary. For example, <a href=\"\/products\/AlwaysUp\/Plugins\/check-web-server-for-5XX-errors.bat\" target=\"_blank\" rel=\"noopener noreferrer\">this sample &#8220;sanity check plugin&#8221; script below<\/a> signals a restart when it detects a server error (500-599).\n<\/p>\n<p>\nEnjoy!\n<\/p>\n<p><!-- HTML generated using hilite.me --><\/p>\n<div style=\"background: #ffffff; overflow:auto;width:auto;border:solid gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;\">\n<pre style=\"margin: 0; line-height: 125%;\"><span><\/span>@<span style=\"color: #080; font-weight: bold\">echo<\/span> off\r\n:<span style=\"color: #888\">: This batch file uses the http-ping application to detect when<\/span>\r\n:<span style=\"color: #888\">: a web server is not responding, or responds with a 5XX status<\/span>\r\n:<span style=\"color: #888\">: code. It returns 0 if the server responds properly and 1 if not.<\/span>\r\n:<span style=\"color: #888\">: It is intended for use with AlwaysUp<\/span>\r\n:<span style=\"color: #888\">: (https:\/\/www.coretechnologies.com\/products\/AlwaysUp\/)<\/span>\r\n:<span style=\"color: #888\">: or Service Protector<\/span>\r\n:<span style=\"color: #888\">: (https:\/\/www.coretechnologies.com\/products\/ServiceProtector\/).<\/span>\r\n:<span style=\"color: #888\">: Copyright \u00a9 Core Technologies Consulting, LLC. All<\/span>\r\n:<span style=\"color: #888\">: rights reserved.<\/span>\r\n\r\n\r\n:<span style=\"color: #888\">: Here are a few variables that you should adjust.<\/span>\r\n:<span style=\"color: #888\">: ** Please specify the URL you wish to ping, and the full path<\/span>\r\n:<span style=\"color: #888\">: to the http-ping executable on your system **<\/span>\r\n<span style=\"color: #080; font-weight: bold\">SET<\/span> <span style=\"color: #963\">url<\/span>=http:\/\/localhost:80\r\n<span style=\"color: #080; font-weight: bold\">SET<\/span> <span style=\"color: #963\">http-ping-exe-path<\/span>=<span style=\"background-color: #FFF0F0\">&quot;C:\\Temp\\http-ping.exe&quot;<\/span>\r\n:<span style=\"color: #888\">: num-times-to-ping == The number of ping attempts that will be<\/span>\r\n:<span style=\"color: #888\">: made. The default of 5 is probably OK, but you can increase<\/span>\r\n:<span style=\"color: #888\">: it if errors are frequent (but tolerable).<\/span>\r\n<span style=\"color: #080; font-weight: bold\">SET<\/span> <span style=\"color: #963\">num-times-to-ping<\/span>=5\r\n:<span style=\"color: #888\">: num-seconds-between-pings == The time to wait between ping<\/span>\r\n:<span style=\"color: #888\">: attempts. Increase this to give your server more time to get<\/span>\r\n:<span style=\"color: #888\">: back on its feet after an error.<\/span>\r\n<span style=\"color: #080; font-weight: bold\">SET<\/span> <span style=\"color: #963\">num-seconds-between-pings<\/span>=10\r\n\r\n\r\n:<span style=\"color: #888\">: Loop &quot;num-times-to-ping&quot; times.<\/span>\r\n<span style=\"color: #080; font-weight: bold\">FOR<\/span> <span style=\"color: #080; font-weight: bold\">\/L<\/span> <span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">%%<\/span>X <span style=\"color: #080; font-weight: bold\">IN<\/span> (<span style=\"color: #00D; font-weight: bold\">1<\/span>,<span style=\"color: #00D; font-weight: bold\">1<\/span>,<span style=\"color: #963\">%num-times-to-ping%<\/span>) <span style=\"color: #080; font-weight: bold\">DO<\/span> <span style=\"color: #080; font-weight: bold\">CALL<\/span> :<span style=\"color: #970; font-weight: bold\">loopbody<\/span> <span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">%%<\/span>X\r\n\r\n\r\n:<span style=\"color: #888\">: If we get here, then all ping attempts failed.<\/span>\r\n<span style=\"color: #080; font-weight: bold\">echo<\/span> All <span style=\"color: #963\">%num-times-to-ping%<\/span> attempts of http-ping failed<span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">^!<\/span> <span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">^<\/span>\r\n<span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">E<\/span>xiting with 1.\r\n<span style=\"color: #080; font-weight: bold\">exit<\/span> 1\r\n\r\n\r\n:<span style=\"color: #970; font-weight: bold\">loopbody<\/span>\r\n:<span style=\"color: #888\">: Ping your web server once, returning the HTTP status code<\/span>\r\n:<span style=\"color: #888\">: (or 0 if the ping failed to connect).<\/span>\r\n<span style=\"color: #963\">%http-ping-exe-path%<\/span> -e -n 1 <span style=\"color: #963\">%url%<\/span>\r\n:<span style=\"color: #888\">: http-ping returns the HTTP status code or 0 if the ping<\/span>\r\n:<span style=\"color: #888\">: failed to connect. The list of HTTP status codes is<\/span>\r\n:<span style=\"color: #888\">: described here:<\/span>\r\n:<span style=\"color: #888\">: http:\/\/en.wikipedia.org\/wiki\/List_of_HTTP_status_codes<\/span>\r\n:<span style=\"color: #888\">: For this script, we&#39;ll panic on 0 or 5XX (server error)<\/span>\r\n:<span style=\"color: #888\">: and consider all other codes as a success.<\/span>\r\n<span style=\"color: #080; font-weight: bold\">IF<\/span> <span style=\"color: #963\">%ERRORLEVEL%<\/span> <span style=\"color: #000; font-weight: bold\">GTR<\/span> 0 (\r\n   <span style=\"color: #080; font-weight: bold\">IF<\/span> <span style=\"color: #963\">%ERRORLEVEL%<\/span> <span style=\"color: #000; font-weight: bold\">LSS<\/span> 500 (\r\n      <span style=\"color: #080; font-weight: bold\">echo<\/span> http-ping returned <span style=\"color: #963\">%ERRORLEVEL%<\/span> - not an error. <span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">^<\/span>\r\n<span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">E<\/span>xiting with 0.\r\n      <span style=\"color: #080; font-weight: bold\">exit<\/span> 0\r\n   ) <span style=\"color: #080; font-weight: bold\">else<\/span> <span style=\"color: #080; font-weight: bold\">IF<\/span> <span style=\"color: #963\">%ERRORLEVEL%<\/span> <span style=\"color: #000; font-weight: bold\">GTR<\/span> 599 (\r\n      <span style=\"color: #080; font-weight: bold\">echo<\/span> http-ping returned <span style=\"color: #963\">%ERRORLEVEL%<\/span> - not an error. <span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">^<\/span>\r\n<span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">E<\/span>xiting with 0.\r\n      <span style=\"color: #080; font-weight: bold\">exit<\/span> 0\r\n   )\r\n)\r\n<span style=\"color: #080; font-weight: bold\">echo<\/span> On attempt #<span style=\"color: #963\">%1<\/span>, http-ping returned <span style=\"color: #963\">%ERRORLEVEL%<\/span> - an error.\r\n:<span style=\"color: #888\">: If this was not the last attempt, pause before trying again.<\/span>\r\n:<span style=\"color: #888\">: Since DOS doesn&#39;t have a &quot;sleep&quot; command, use ping with an<\/span>\r\n:<span style=\"color: #888\">: invalid address and a timeout (in milliseconds) to wait for<\/span>\r\n:<span style=\"color: #888\">: a while. You can adjust the timeout value<\/span>\r\n:<span style=\"color: #888\">: (num-seconds-between-pings) above.<\/span>\r\n<span style=\"color: #080; font-weight: bold\">IF<\/span> <span style=\"color: #963\">%1<\/span> <span style=\"color: #000; font-weight: bold\">LSS<\/span> <span style=\"color: #963\">%num-times-to-ping%<\/span> (\r\n   <span style=\"color: #080; font-weight: bold\">SET<\/span> <span style=\"color: #080; font-weight: bold\">\/A<\/span> <span style=\"color: #963\">milliseconds<\/span><span style=\"color: #333\">=%<\/span><span style=\"color: #963\">num<\/span><span style=\"color: #333\">-<\/span><span style=\"color: #963\">seconds<\/span><span style=\"color: #333\">-<\/span><span style=\"color: #963\">between<\/span><span style=\"color: #333\">-<\/span><span style=\"color: #963\">pings<\/span><span style=\"color: #333\">%<\/span> <span style=\"color: #333\">*<\/span> <span style=\"color: #00D; font-weight: bold\">1000<\/span>\r\n   <span style=\"color: #080; font-weight: bold\">echo<\/span> Pausing for <span style=\"color: #963\">%num-seconds-between-pings%<\/span> second<span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">^(<\/span>s<span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">^)^<\/span>\r\n<span style=\"color: #666; font-weight: bold; background-color: #FFF0F0\">b<\/span>efore the next attempt...\r\n   ping 1.1.1.1 -n 1 -w <span style=\"color: #963\">%milliseconds%<\/span> &gt; nul\r\n)\r\n<\/pre>\n<\/div>\n<div style=\"margin-top:30px\" align=\"center\">\n<div class=\"cta-button-1\">\n<table role=\"presentation\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" align=\"left\">\n<tbody>\n<tr>\n<td align=\"center\"><a href=\"\/blog\/tag\/http-ping\/\" title=\"Click to read more articles about http-ping\"><span><nobr>More articles about http-ping&#8230;<\/nobr><\/span><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<!-- relpost-thumb-wrapper --><div class=\"relpost-thumb-wrapper\"><!-- filter-class --><div class=\"relpost-thumb-container\"><style>.relpost-block-single-image, .relpost-post-image { margin-bottom: 10px; }<\/style><h3>You may also like...<\/h3><div style=\"clear: both\"><\/div><div style=\"clear: both\"><\/div><!-- relpost-block-container --><div class=\"relpost-block-container relpost-block-column-layout\" style=\"--relposth-columns: 3;--relposth-columns_t: 2; --relposth-columns_m: 2\"><a href=\"https:\/\/www.coretechnologies.com\/blog\/service-security-editor\/change-windows-service-permissions-gui\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Change Windows Service Permissions with Service Security Editor\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/gear-document-150x150.png\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Change Windows Service Permissions with Service Security Editor<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/alwaysup\/version-16-5-released\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"AlwaysUp 16.5: Easily Install nginx as a Service, Survive Resource Leaks, and more\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/new-banner-150x150-1.webp\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">AlwaysUp 16.5: Easily Install nginx as a Service, Survive Resource Leaks, and more<\/h2><\/div><\/div><\/a><a href=\"https:\/\/www.coretechnologies.com\/blog\/service-protector\/version-9-released\/\"class=\"relpost-block-single\" ><div class=\"relpost-custom-block-single\"><img decoding=\"async\" loading=\"lazy\" class=\"relpost-block-single-image\" alt=\"Service Protector 9.0: Easily Import Many Windows Services\"  src=\"https:\/\/www.coretechnologies.com\/blog\/wp-content\/uploads\/new-release-150x150-1.webp\" style=\"aspect-ratio:1\/1\" style=\"aspect-ratio:1\/1\"><\/img><div class=\"relpost-block-single-text\"  style=\"height: 75px;font-family: Arial;  font-size: 12px;  color: #333333;\"><h2 class=\"relpost_card_title\">Service Protector 9.0: Easily Import Many Windows Services<\/h2><\/div><\/div><\/a><\/div><!-- close relpost-block-container --><div style=\"clear: both\"><\/div><\/div><!-- close filter class --><\/div><!-- close relpost-thumb-wrapper -->","protected":false},"excerpt":{"rendered":"<p>Savvy programmers and administrators often use our free http-ping command line utility to check that their web servers up and serving pages. http-ping&#8217;s return code (the percentage of page downloads that succeeded) lets them know when the web server is &hellip; <a href=\"https:\/\/www.coretechnologies.com\/blog\/http-ping\/http-ping-6-0-returns-http-status-code\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":8568,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[89,109],"class_list":["post-153","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-http-ping","tag-http-ping","tag-new-release"],"_links":{"self":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/153","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=153"}],"version-history":[{"count":3,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/153\/revisions"}],"predecessor-version":[{"id":13378,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/153\/revisions\/13378"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media\/8568"}],"wp:attachment":[{"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=153"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=153"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.coretechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=153"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}