Link to home
Start Free TrialLog in
Avatar of Daran_M
Daran_M

asked on

network check

HI experts...
  I am trying to creating an application in visual basic such that if the communication link (LAN Cable) between 2 pc's is not available(broken/removed) then it must trigger a message. I think I might have to use windows API for that but I am not too sure. Can you all please help me? I am really looking forward to your comments.
Avatar of Melih SARICA
Melih SARICA
Flag of Türkiye image

U can ping the Computer .. and when u dont get an reply trigger an event...

here is a simple ping code for VB ( Thanx to PLG)

Public Function Ping(sAddress As String, _
                     sDataToSend As String, _
                     ECHO As ICMP_ECHO_REPLY) As Long

   Dim hPort As Long
   Dim dwAddress As Long
   
  'convert the address into a long representation
   dwAddress = inet_addr(sAddress)
   
  'if dwAddress is valid
   If dwAddress <> INADDR_NONE Then
   
     'open a port
      hPort = IcmpCreateFile()
     
     'and if successful,
      If hPort Then
     
        'ping it.
         Call IcmpSendEcho(hPort, _
                           dwAddress, _
                           sDataToSend, _
                           Len(sDataToSend), _
                           0, _
                           ECHO, _
                           Len(ECHO), _
                           glngPingTime)

        'return the status as ping success
         Ping = ECHO.status

        'close the port handle
         Call IcmpCloseHandle(hPort)
     
      End If  'If hPort
     
   Else:
   
        'the address format was probably invalid
         Ping = INADDR_NONE
         
   End If
 
End Function
Avatar of developer007
developer007

Yeh..

 Some times the connection is proper and ping may not happen also..


   
Avatar of Daran_M

ASKER

HI experts,
         thanks for the reply. Isn’t there any API function that can be used to achieve this? thanks once again for the reply.
ASKER CERTIFIED SOLUTION
Avatar of Melih SARICA
Melih SARICA
Flag of Türkiye image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial