PDA

View Full Version : How Can I Determine Network Connectivity?



EricJK
07-14-2006, 12:42 PM
Does anyone know how to determine network connectivity? I'd like to know if a particular server is available on the network in my installer.

Thanks in advance,
Eric

AndrewRich
07-14-2006, 01:53 PM
Does anyone know how to determine network connectivity? I'd like to know if a particular server is available on the network in my installer. Do you want to know if... the target machine has an IP address?
can ping the particular server?
can log in to the server with specified credentials?
a specific share exists on the server? Each of these would need a different solution.

EricJK
07-14-2006, 01:56 PM
Ping would be sufficient as I just want to know if it's available on the network.

AndrewRich
07-14-2006, 02:22 PM
#include "ifx.h"

#define THE_SERVER "192.168.15.200"

STRING szProgram, szTxtFile, szCmdLine, svString, svResult;
NUMBER nOptions, nRC;
LIST listTxtFile, listTokens;

program

// first get the info into a text file
GetEnvVar ( "COMSPEC", szProgram );
szTxtFile = SUPPORTDIR ^ "serverping.txt";
Sprintf ( szCmdLine, "/c ping -n 1 %s | find /i \"Packets\" > %s", THE_SERVER, szTxtFile );
nOptions = LAAW_OPTION_WAIT | LAAW_OPTION_HIDDEN;
LaunchAppAndWait ( szProgram, szCmdLine, nOptions );

// then load the text file into a list
listTxtFile = ListCreate ( STRINGLIST );
ListReadFromFile ( listTxtFile, szTxtFile );

// parse the list to get the result
nRC = ListGetFirstString ( listTxtFile, svString );
if ( svString != "" ) then
listTokens = ListCreate ( STRINGLIST );
StrGetTokens ( listTokens, svString, "," );
ListSetIndex ( listTokens, 1 );
ListCurrentString ( listTokens, svResult );
ListDestroy ( listTokens );
if ( svResult != "" ) then
listTokens = ListCreate ( STRINGLIST );
StrGetTokens ( listTokens, svResult, " =" );
ListSetIndex ( listTokens, LISTLAST );
ListCurrentString ( listTokens, svResult );
ListDestroy ( listTokens );
else
Sprintf ( svResult, "%s could not be found!", THE_SERVER );
endif;
else
Sprintf ( svResult, "%s could not be found!", THE_SERVER );
endif;

// show the result
MessageBox ( "Result: " + svResult, INFORMATION );

// cleanup
ListDestroy ( listTxtFile );
DeleteFile ( szTxtFile );

endprogram There are three possible results: "" (empty string) means the host could not be found.
0 means the server did not return the ping request
1 means the server did return the ping request

EricJK
07-14-2006, 03:42 PM
Andrew,
It works. Thank you very much for the help!
Eric

Mrunmayee
05-05-2010, 04:02 AM
Andrew,
Great work!!!
It worked perfectly for me.
Thanks a lot.