Check if the internet connection is active

When using HTTP Request automations in NAV you have to call the send method. But if the internet is not active this can result in an error.
A user on mibuso had this problem.

So a little function to check if the internet is active could be a real help.
Well here you go, a ready to use function:

pingFlag              Integer
WindowStyle           Integer
WaitForReturn         Boolean
wShell                Automation  'Windows Script Host Model'.WshShell

And the function itself:

isSiteActive(SiteURL : Text[250]) : Boolean

  SiteURL := COPYSTR(SiteURL,8);
IF LOWERCASE(COPYSTR(SiteURL,1,8)) = 'https://' THEN
  SiteURL := COPYSTR(SiteURL,9);

IF STRPOS(SiteURL,'\') <> 0 THEN
  SiteURL := COPYSTR(SiteURL,1,STRPOS(SiteURL,'\')-1);
IF STRPOS(SiteURL,'/') <> 0 THEN
  SiteURL := COPYSTR(SiteURL,1,STRPOS(SiteURL,'/')-1);

WindowStyle := 0;
WaitForReturn := TRUE;
pingFlag := wShell.Run('ping -n 1 ' + SiteURL,WindowStyle,WaitForReturn);
IF pingFlag = 0 THEN

Please mind that some sites do not allow to be pinged. So a general website ping could be a solution (When I tested here, does not respond, did respond).


One thought on “Check if the internet connection is active

  1. Pingback: Check if the internet connection is active |

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.