Server monitoring with VS6 SP5

Posted on 2006-11-01
Last Modified: 2016-08-29
I have created a simple form that displays all of my server names
in order via labels. Beside each I have two hidden images, one red
button and one green button. On form load I have all image properties
set to visible=false.

I have created a text box beside each server name and have hidden it
and I need to add the server ip address in these textboxes.(Somehow?)

I want the form , upon load, to ping each server ip address and depending
on the results want which ever image is applicable, (red(Failure) or green)Success)
to change properties to visible=true so that it is displayed on the screen for all to see
beside the correct server name.

Can anyone help me out on this ?

Question by:ittechie100
  • 8
LVL 15

Expert Comment

ID: 17855122
vb 6.0?
Here is the Module Code... Just Copy and paste it to module...

Option Explicit

'Icmp constants converted from

Private Const ICMP_SUCCESS As Long = 0
Private Const ICMP_STATUS_BUFFER_TO_SMALL = 11001                   'Buffer Too Small
Private Const ICMP_STATUS_DESTINATION_NET_UNREACH = 11002           'Destination Net Unreachable
Private Const ICMP_STATUS_DESTINATION_HOST_UNREACH = 11003          'Destination Host Unreachable
Private Const ICMP_STATUS_DESTINATION_PROTOCOL_UNREACH = 11004      'Destination Protocol Unreachable
Private Const ICMP_STATUS_DESTINATION_PORT_UNREACH = 11005          'Destination Port Unreachable
Private Const ICMP_STATUS_NO_RESOURCE = 11006                       'No Resources
Private Const ICMP_STATUS_BAD_OPTION = 11007                        'Bad Option
Private Const ICMP_STATUS_HARDWARE_ERROR = 11008                    'Hardware Error
Private Const ICMP_STATUS_LARGE_PACKET = 11009                      'Packet Too Big
Private Const ICMP_STATUS_REQUEST_TIMED_OUT = 11010                 'Request Timed Out
Private Const ICMP_STATUS_BAD_REQUEST = 11011                       'Bad Request
Private Const ICMP_STATUS_BAD_ROUTE = 11012                         'Bad Route
Private Const ICMP_STATUS_TTL_EXPIRED_TRANSIT = 11013               'TimeToLive Expired Transit
Private Const ICMP_STATUS_TTL_EXPIRED_REASSEMBLY = 11014            'TimeToLive Expired Reassembly
Private Const ICMP_STATUS_PARAMETER = 11015                         'Parameter Problem
Private Const ICMP_STATUS_SOURCE_QUENCH = 11016                     'Source Quench
Private Const ICMP_STATUS_OPTION_TOO_BIG = 11017                    'Option Too Big
Private Const ICMP_STATUS_BAD_DESTINATION = 11018                   'Bad Destination
Private Const ICMP_STATUS_NEGOTIATING_IPSEC = 11032                 'Negotiating IPSEC
Private Const ICMP_STATUS_GENERAL_FAILURE = 11050                   'General Failure

Public Const WINSOCK_ERROR = "Windows Sockets not responding correctly."
Public Const WSA_SUCCESS = 0
Public Const WS_VERSION_REQD As Long = &H101

'Clean up sockets.

Private Declare Function WSACleanup Lib "WSOCK32.DLL" () As Long

'Open the socket connection.
Private Declare Function WSAStartup Lib "WSOCK32.DLL" (ByVal wVersionRequired As Long, lpWSADATA As WSADATA) As Long

'Create a handle on which Internet Control Message Protocol (ICMP) requests can be issued.
Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long

'Convert a string that contains an (Ipv4) Internet Protocol dotted address into a correct address.
Private Declare Function inet_addr Lib "WSOCK32.DLL" (ByVal cp As String) As Long

'Close an Internet Control Message Protocol (ICMP) handle that IcmpCreateFile opens.

Private Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal IcmpHandle As Long) As Long

'Information about the Windows Sockets implementation
Private Type WSADATA
   wVersion As Integer
   wHighVersion As Integer
   szDescription(0 To 256) As Byte
   szSystemStatus(0 To 128) As Byte
   iMaxSockets As Long
   iMaxUDPDG As Long
   lpVendorInfo As Long
End Type

'Send an Internet Control Message Protocol (ICMP) echo request, and then return one or more replies.
Private Declare Function IcmpSendEcho Lib "icmp.dll" _
   (ByVal IcmpHandle As Long, _
    ByVal DestinationAddress As Long, _
    ByVal RequestData As String, _
    ByVal RequestSize As Long, _
    ByVal RequestOptions As Long, _
    ReplyBuffer As ICMP_ECHO_REPLY, _
    ByVal ReplySize As Long, _
    ByVal Timeout As Long) As Long
'This structure describes the options that will be included in the header of an IP packet.
   Ttl             As Byte
   Tos             As Byte
   Flags           As Byte
   OptionsSize     As Byte
   OptionsData     As Long
End Type

'This structure describes the data that is returned in response to an echo request.
   address         As Long
   Status          As Long
   RoundTripTime   As Long
   DataSize        As Long
   Reserved        As Integer
   ptrData                 As Long
   Options        As IP_OPTION_INFORMATION
   Data            As String * 250
End Type

'-- Ping a string representation of an IP address.
' -- Return a reply.
' -- Return long code.
Public Function ping(sAddress As String, Reply As ICMP_ECHO_REPLY) As Long

Dim hIcmp As Long
Dim lAddress As Long
Dim lTimeOut As Long
Dim StringToSend As String

'Short string of data to send
StringToSend = "hello"

'ICMP (ping) timeout
lTimeOut = 1000 'ms

'Convert string address to a long representation.
lAddress = inet_addr(sAddress)

If (lAddress <> -1) And (lAddress <> 0) Then
    'Create the handle for ICMP requests.
    hIcmp = IcmpCreateFile()
    If hIcmp Then
        'Ping the destination IP address.
        Call IcmpSendEcho(hIcmp, lAddress, StringToSend, Len(StringToSend), 0, Reply, Len(Reply), lTimeOut)

        'Reply status
        ping = Reply.Status
        'Close the Icmp handle.
        IcmpCloseHandle hIcmp
        Debug.Print "failure opening icmp handle."
        ping = -1
    End If
    ping = -1
End If

End Function

'Clean up the sockets.
Public Sub SocketsCleanup()
End Sub

'Get the sockets ready.
Public Function SocketsInitialize() As Boolean


   SocketsInitialize = WSAStartup(WS_VERSION_REQD, WSAD) = ICMP_SUCCESS

End Function

'Convert the ping response to a message that you can read easily from constants.
'For more information about these constants, visit the following Microsoft Web site:

Public Function EvaluatePingResponse(PingResponse As Long) As String

  Select Case PingResponse
  Case ICMP_SUCCESS: EvaluatePingResponse = "Success!"
  'Some error occurred
  Case ICMP_STATUS_BUFFER_TO_SMALL:    EvaluatePingResponse = "Buffer Too Small"
  Case ICMP_STATUS_DESTINATION_NET_UNREACH: EvaluatePingResponse = "Destination Net Unreachable"
  Case ICMP_STATUS_DESTINATION_HOST_UNREACH: EvaluatePingResponse = "Destination Host Unreachable"
  Case ICMP_STATUS_DESTINATION_PROTOCOL_UNREACH: EvaluatePingResponse = "Destination Protocol Unreachable"
  Case ICMP_STATUS_DESTINATION_PORT_UNREACH: EvaluatePingResponse = "Destination Port Unreachable"
  Case ICMP_STATUS_NO_RESOURCE: EvaluatePingResponse = "No Resources"
  Case ICMP_STATUS_BAD_OPTION: EvaluatePingResponse = "Bad Option"
  Case ICMP_STATUS_HARDWARE_ERROR: EvaluatePingResponse = "Hardware Error"
  Case ICMP_STATUS_LARGE_PACKET: EvaluatePingResponse = "Packet Too Big"
  Case ICMP_STATUS_REQUEST_TIMED_OUT: EvaluatePingResponse = "Request Timed Out"
  Case ICMP_STATUS_BAD_REQUEST: EvaluatePingResponse = "Bad Request"
  Case ICMP_STATUS_BAD_ROUTE: EvaluatePingResponse = "Bad Route"
  Case ICMP_STATUS_TTL_EXPIRED_TRANSIT: EvaluatePingResponse = "TimeToLive Expired Transit"
  Case ICMP_STATUS_TTL_EXPIRED_REASSEMBLY: EvaluatePingResponse = "TimeToLive Expired Reassembly"
  Case ICMP_STATUS_PARAMETER: EvaluatePingResponse = "Parameter Problem"
  Case ICMP_STATUS_SOURCE_QUENCH: EvaluatePingResponse = "Source Quench"
  Case ICMP_STATUS_OPTION_TOO_BIG: EvaluatePingResponse = "Option Too Big"
  Case ICMP_STATUS_BAD_DESTINATION: EvaluatePingResponse = "Bad Destination"
  Case ICMP_STATUS_NEGOTIATING_IPSEC: EvaluatePingResponse = "Negotiating IPSEC"
  Case ICMP_STATUS_GENERAL_FAILURE: EvaluatePingResponse = "General Failure"
  'Unknown error occurred
  Case Else: EvaluatePingResponse = "Unknown Response"
  End Select

End Function

LVL 15

Accepted Solution

JackOfPH earned 500 total points
ID: 17855133
'**********And This is the Form Code
Just Copy and Paste it....

Private Sub Form_Load()
'Do this in to all your server

If UCase(PingComputer(Me.txtServer1IP.Text)) = UCase("success!") Then
    Me.txtServer1IP.BackColor = vbGreen
    Me.txtServer1IP.BackColor = vbRed
End If

If UCase(PingComputer(Me.txtServer2IP.Text)) = UCase("success!") Then
    Me.txtServer2IP.BackColor = vbGreen
    Me.txtServer2IP.BackColor = vbRed
End If

Me.PicServer1.Visible = True
Me.txtServer1IP.Visible = True

Me.PicServer2.Visible = True
Me.txtServer2IP.Visible = True

End Sub

Function PingComputer(ByVal IPADDRESS As String) As String
   Dim lngSuccess As Long
   Dim strIPAddress As String
   'Get the sockets ready.
   If SocketsInitialize() Then
    'Address to ping
    strIPAddress = IPADDRESS
    'Ping the IP that is passing the address and get a reply.
    lngSuccess = ping(strIPAddress, Reply)
    'Display the results.
    PingComputer = EvaluatePingResponse(lngSuccess)
    'Clean up the sockets.
   'Winsock error failure, initializing the sockets.
   PingComputer = WINSOCK_ERROR
   End If
End Function
LVL 15

Expert Comment

ID: 17855140
Post if you have question or comment...

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

LVL 15

Expert Comment

ID: 17855763
I will send you a complete example once the ee-stuff is working...

Author Comment

ID: 17857982
Thanks, I will need it. I still am learning. I need working examples I caxn review and that I found helps
me more in understanding the code. Especially since I've not had any professional training...

LVL 15

Expert Comment

ID: 17863098
I will give you one...
LVL 15

Expert Comment

ID: 17863230
The Code I gave you is a working example...

The First Comment is a module code... Just copy and paste it...
The Second Comment is the form load... just copy and paste it.

On the form ...
Add two textboxes... Name the first textbox with txtServer1IP. The second textbox is txtServer2IP.
Add Two Picture Box... Name the first Picturebox with PicServer1 and the second is PicServer2.

Make the textboxes and the Picturebox visible property to false.
LVL 15

Expert Comment

ID: 17863236
ee-stuff is not working so I will give you one...
LVL 15

Expert Comment

ID: 17871380
Here is a working example ... 

Just post if you have comment...

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question