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. Determine when I am connected on LAN

Determine when I am connected on LAN

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadmin
8 Posts 4 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.
  • A Offline
    A Offline
    Alan Martinis
    wrote on last edited by
    #1

    Please, If someone know how can I determine within my application if network cable is unplugged ? Thank you ! Alan

    RaviBeeR A 2 Replies Last reply
    0
    • A Alan Martinis

      Please, If someone know how can I determine within my application if network cable is unplugged ? Thank you ! Alan

      RaviBeeR Offline
      RaviBeeR Offline
      RaviBee
      wrote on last edited by
      #2

      See InternetGetConnectedState(). /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

      A 1 Reply Last reply
      0
      • A Alan Martinis

        Please, If someone know how can I determine within my application if network cable is unplugged ? Thank you ! Alan

        A Offline
        A Offline
        Alexander M
        wrote on last edited by
        #3

        check the ip interfaces.. if the network cable is unplugged, there wont be any ip interface for the adapter(on win2k and later). Don't try it, just do it! ;-)

        A 1 Reply Last reply
        0
        • RaviBeeR RaviBee

          See InternetGetConnectedState(). /ravi Let's put "civil" back in "civilization" Home | Articles | Freeware | Music ravib@ravib.com

          A Offline
          A Offline
          Alexander M
          wrote on last edited by
          #4

          i think this wont solve all problems.. if the lan isnt used for internet, i suppose this wont work! Don't try it, just do it! ;-)

          1 Reply Last reply
          0
          • A Alexander M

            check the ip interfaces.. if the network cable is unplugged, there wont be any ip interface for the adapter(on win2k and later). Don't try it, just do it! ;-)

            A Offline
            A Offline
            Alan Martinis
            wrote on last edited by
            #5

            Ok, thank you, sound's great, but since I'm almost new in this world, can you please give me some line of code ? Tnx

            P A 2 Replies Last reply
            0
            • A Alan Martinis

              Ok, thank you, sound's great, but since I'm almost new in this world, can you please give me some line of code ? Tnx

              P Offline
              P Offline
              pma
              wrote on last edited by
              #6

              Maybe you use this code, its working for all known cases. ok, its working at least for all my cases bye mario 1) InternetCheckConnection ( Checks for Google ) 2) InternetAttemptConnect ( Windows Function ) 3) IsModem Connected ( Modem Connection ) 4) gethostbyname ( Google ) 5) InternetGetConnectedState ( LAN ) 6) Dont check for Internetconnection // Check if Online BOOL WINAPI IsADSLConnected() { LPDWORD lpdwFlags=0; DWORD dwReserved=0; RASCONN rc; rc.dwSize = sizeof(rc); DWORD numConns=0; DWORD size=0; DWORD res; do { switch(g_m_ConMode) { case 0: try { g_IsConnected=InternetCheckConnection("http://www.google.com",FLAG_ICC_FORCE_CONNECTION ,0); } catch(...) { g_m_ConMode = 4; } break; case 1: res = InternetAttemptConnect(0); if(res == ERROR_SUCCESS) g_IsConnected = 1; else g_IsConnected = 0; break; case 2: // Enumerate the connections. res = RasEnumConnections(&rc, &size, &numConns); if (numConns > 0 || InternetGetConnectedState(lpdwFlags,dwReserved)) g_IsConnected = 1; else g_IsConnected = 0; break; case 3: if (gethostbyname ("www.google.com")) g_IsConnected = 1; else g_IsConnected = 0; break; case 4: g_IsConnected = 0; if (::InternetGetConnectedState (&dwReserved, 0)) { if ((dwReserved & INTERNET_CONNECTION_LAN) || (dwReserved & INTERNET_CONNECTION_MODEM) || (dwReserved & INTERNET_CONNECTION_PROXY)) { g_IsConnected = 1; } } break; case 5: g_IsConnected = 0; break; } Sleep(2500); } while(1); }

              1 Reply Last reply
              0
              • A Alan Martinis

                Ok, thank you, sound's great, but since I'm almost new in this world, can you please give me some line of code ? Tnx

                A Offline
                A Offline
                Alan Martinis
                wrote on last edited by
                #7

                Can you help me also with next one more thing: if I detect that I'm connected on my LAN, how can I measure speed between my pc and server (I know only name of that server). Tnx

                P 1 Reply Last reply
                0
                • A Alan Martinis

                  Can you help me also with next one more thing: if I detect that I'm connected on my LAN, how can I measure speed between my pc and server (I know only name of that server). Tnx

                  P Offline
                  P Offline
                  pma
                  wrote on last edited by
                  #8

                  try to use SNMP, but thats not trivial, i'am currently working on the same thing ;-)

                  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