How to find if a particular system is active or not in a LAN?
-
Hello friends, this me back with a question. I ve got a code snippet for finding the list of systems in a LAN.It lists the computer name and the IP address. Now i wanted to know how i can find the status of the system ie. if it is active or not. here is the piece i used to found the systems: for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++ ) if ( NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY ) { if ( NetResource->lpRemoteName ) { CString strFullName = NetResource->lpRemoteName; if ( 0 == strFullName.Left(2).Compare("\\\\") ) strFullName = strFullName.Right(strFullName.GetLength()-2); gethostname( szHostName, strlen( szHostName ) ); host = gethostbyname(strFullName); ptr = (struct in_addr *) host->h_addr_list[0]; int a = ptr->S_un.S_un_b.s_b1; // 211.40.35.76 split up like this. int b = ptr->S_un.S_un_b.s_b2; // 40 int c = ptr->S_un.S_un_b.s_b3; // 35 int d = ptr->S_un.S_un_b.s_b4; // 76 lpszSystemInfo = tchBuffer; // Get and display the user name. GetUserName(lpszSystemInfo, &cchBuff); strTemp.Format("%s --> %d.%d.%d.%d",strFullName,a,b,c,d); pList->AddString(strTemp); } } } this is a downloaded code friends. but still i want to know how.if we can find the IP address, then there must be a way to find its status. Pls do let me know if anyone of you know this.Thanks (in anticipation) Malini
-
Hello friends, this me back with a question. I ve got a code snippet for finding the list of systems in a LAN.It lists the computer name and the IP address. Now i wanted to know how i can find the status of the system ie. if it is active or not. here is the piece i used to found the systems: for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++ ) if ( NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY ) { if ( NetResource->lpRemoteName ) { CString strFullName = NetResource->lpRemoteName; if ( 0 == strFullName.Left(2).Compare("\\\\") ) strFullName = strFullName.Right(strFullName.GetLength()-2); gethostname( szHostName, strlen( szHostName ) ); host = gethostbyname(strFullName); ptr = (struct in_addr *) host->h_addr_list[0]; int a = ptr->S_un.S_un_b.s_b1; // 211.40.35.76 split up like this. int b = ptr->S_un.S_un_b.s_b2; // 40 int c = ptr->S_un.S_un_b.s_b3; // 35 int d = ptr->S_un.S_un_b.s_b4; // 76 lpszSystemInfo = tchBuffer; // Get and display the user name. GetUserName(lpszSystemInfo, &cchBuff); strTemp.Format("%s --> %d.%d.%d.%d",strFullName,a,b,c,d); pList->AddString(strTemp); } } } this is a downloaded code friends. but still i want to know how.if we can find the IP address, then there must be a way to find its status. Pls do let me know if anyone of you know this.Thanks (in anticipation) Malini
Malini Nair wrote:
Now i wanted to know how i can find the status of the system ie. if it is active or not.
(If I understand your question correctly ...) What about the function:
FILE *_popen(const char *command,const char *mode)
You can uses this function to ping the other machine, and know the status.#include #include int main( void ) { char psBuffer[128]; FILE *pPipe; if( (pPipe = _popen( "ping 192.168.0.1", "rt" )) == NULL ) exit( 1 ); /* Read pipe until end of file. */ while( !feof( pPipe ) ) { if( fgets( psBuffer, 128, pPipe ) != NULL ) printf( psBuffer ); } /* Close pipe and print return value of pPipe. */ printf( "\nProcess returned %d\n", _pclose( pPipe ) ); }
Hope this helps .. Regards,
The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^
-
Hello friends, this me back with a question. I ve got a code snippet for finding the list of systems in a LAN.It lists the computer name and the IP address. Now i wanted to know how i can find the status of the system ie. if it is active or not. here is the piece i used to found the systems: for ( unsigned int i = 0; i < BufferSize/sizeof(NETRESOURCE); i++, NetResource++ ) if ( NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY ) { if ( NetResource->lpRemoteName ) { CString strFullName = NetResource->lpRemoteName; if ( 0 == strFullName.Left(2).Compare("\\\\") ) strFullName = strFullName.Right(strFullName.GetLength()-2); gethostname( szHostName, strlen( szHostName ) ); host = gethostbyname(strFullName); ptr = (struct in_addr *) host->h_addr_list[0]; int a = ptr->S_un.S_un_b.s_b1; // 211.40.35.76 split up like this. int b = ptr->S_un.S_un_b.s_b2; // 40 int c = ptr->S_un.S_un_b.s_b3; // 35 int d = ptr->S_un.S_un_b.s_b4; // 76 lpszSystemInfo = tchBuffer; // Get and display the user name. GetUserName(lpszSystemInfo, &cchBuff); strTemp.Format("%s --> %d.%d.%d.%d",strFullName,a,b,c,d); pList->AddString(strTemp); } } } this is a downloaded code friends. but still i want to know how.if we can find the IP address, then there must be a way to find its status. Pls do let me know if anyone of you know this.Thanks (in anticipation) Malini
How did you get your array of NETRESOURCE structs? If an item is in the array then I would assume it is active. What do you mean by active status?
"If you can dodge a wrench, you can dodge a ball."