Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to find if a particular system is active or not in a LAN?

How to find if a particular system is active or not in a LAN?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Malini Nair
    wrote on last edited by
    #1

    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

    P M 2 Replies Last reply
    0
    • M Malini Nair

      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

      P Offline
      P Offline
      Programm3r
      wrote on last edited by
      #2

      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: ^_^

      1 Reply Last reply
      0
      • M Malini Nair

        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

        M Offline
        M Offline
        Mark Salsbery
        wrote on last edited by
        #3

        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."

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups