Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Retriving ICMP statistics using GetIcmpStatistics API

Total Hit ( 2757)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


This code will show you use of GetIcmpStatistics API which can give you some important information regarding ICMP information.

Here is the sample output of this program

# Messages   [in/out] : 9/11
# Error      [in/out] : 0/0
# Redirects  [in/out] : 0/0
# Echos      [in/out] : 1/8
# Unrechable [in/out] : 0/2
# TTLExceeded[in/out] : 0/0
# SrcQuenchs [in/out] : 0/0
# ParaProblem[in/out] : 0/0
# TStampRep  [in/out] : 0/0
# TStampReq  [in/out] : 0/0
# AdrmaskReq [in/out] : 0/0
# AdrmaskRep [in/out] : 0/0

Step-By-Step Example

- Create a standard exe project
- Add the following code in form1

Click here to copy the following block
Option Explicit

Private Const ERROR_SUCCESS = 0&

Private Type MIBICMPSTATS
  dwMsgs As Long
  dwErrors As Long
  dwDestUnreachs As Long
  dwTimeExcds As Long
  dwParmProbs As Long
  dwSrcQuenchs As Long
  dwRedirects As Long
  dwEchos As Long
  dwEchoReps As Long
  dwTimestamps As Long
  dwTimestampReps As Long
  dwAddrMasks As Long
  dwAddrMaskReps As Long
End Type

Private Type MIBICMPINFO
  icmpInStats As MIBICMPSTATS
  icmpOutStats As MIBICMPSTATS
End Type

Private Declare Function GetIcmpStatistics Lib "iphlpapi" (pStats As MIBICMPINFO) As Long

Private Sub Form_Load()
  Call GetIcmpStats
End Sub

Sub GetIcmpStats()
  Dim sMsg As String

  Dim ICMP As MIBICMPINFO, i As Integer

  If GetIcmpStatistics(ICMP) = ERROR_SUCCESS Then
    ' Everything went well, please proceed!
    sMsg = sMsg & "# Messages  [in/out] : " & ICMP.icmpInStats.dwMsgs & "/" & ICMP.icmpOutStats.dwMsgs & vbCrLf
    sMsg = sMsg & "# Error   [in/out] : " & ICMP.icmpInStats.dwErrors & "/" & ICMP.icmpOutStats.dwErrors & vbCrLf
    sMsg = sMsg & "# Redirects [in/out] : " & ICMP.icmpInStats.dwRedirects & "/" & ICMP.icmpOutStats.dwRedirects & vbCrLf
    sMsg = sMsg & "# Echos   [in/out] : " & ICMP.icmpInStats.dwEchos & "/" & ICMP.icmpOutStats.dwEchos & vbCrLf
    sMsg = sMsg & "# Unrechable [in/out] : " & ICMP.icmpInStats.dwDestUnreachs & "/" & ICMP.icmpOutStats.dwDestUnreachs & vbCrLf
    sMsg = sMsg & "# TTLExceeded[in/out] : " & ICMP.icmpInStats.dwTimeExcds & "/" & ICMP.icmpOutStats.dwTimeExcds & vbCrLf
    sMsg = sMsg & "# SrcQuenchs [in/out] : " & ICMP.icmpInStats.dwSrcQuenchs & "/" & ICMP.icmpOutStats.dwSrcQuenchs & vbCrLf
    sMsg = sMsg & "# ParaProblem[in/out] : " & ICMP.icmpInStats.dwParmProbs & "/" & ICMP.icmpOutStats.dwParmProbs & vbCrLf
    sMsg = sMsg & "# TStampRep [in/out] : " & ICMP.icmpInStats.dwTimestampReps & "/" & ICMP.icmpOutStats.dwTimestampReps & vbCrLf
    sMsg = sMsg & "# TStampReq [in/out] : " & ICMP.icmpInStats.dwTimestamps & "/" & ICMP.icmpOutStats.dwTimestamps & vbCrLf
    sMsg = sMsg & "# AdrmaskReq [in/out] : " & ICMP.icmpInStats.dwAddrMasks & "/" & ICMP.icmpOutStats.dwAddrMasks & vbCrLf
    sMsg = sMsg & "# AdrmaskRep [in/out] : " & ICMP.icmpInStats.dwAddrMaskReps & "/" & ICMP.icmpOutStats.dwAddrMaskReps & vbCrLf
  Else
    MsgBox "Unable to retrieve ICMP statistics!"
    Exit Sub
  End If

  MsgBox sMsg

  Debug.Print sMsg
End Sub

- Run the project


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.