HexIcmp quick examples
Visual Basic 5.0
'A simple Ping program
'Be sure to select the Hexillion components
'in the Project|References dialog
Option Explicit
Sub main()
Dim oIcmp As New HexIcmp
Dim oLkup As New HexLookup
Dim lAddr As Long, lRtt As Long
Dim sHost As String, sOut As String
sHost = "www.netscape.com"
lAddr = oLkup.LookUp(sHost)
If 0 <> lAddr Then
oIcmp.Timeout = 2000
lRtt = oIcmp.Ping(lAddr)
If 0 <= lRtt Then
sOut = "Round trip time to "
sOut = sOut & sHost & ": "
sOut = sOut & lRtt & " ms"
MsgBox sOut
Else
MsgBox "No reply to ping"
End If
Else
MsgBox "Lookup of " & sHost & " failed."
End If
End Sub
ASP with VBScript
<%@ LANGUAGE="VBSCRIPT" %>
<HTML>
<HEAD>
<TITLE>HexIcmp Ping example</TITLE>
</HEAD>
<BODY>
<%
set oIcmp = Server.CreateObject("Hexillion.HexIcmp")
set oLkup = Server.CreateObject("Hexillion.HexLookup")
%>
<p>Using Hexillion.HexIcmp that expires
<% = oIcmp.Expires %></p>
<%
sHost = "www.yahoo.com"
lAddr = oLkup.LookUp( sHost )
if 0 = lAddr then
Response.Write( "<p>Lookup of " & sHost )
Response.Write( " failed with error " )
Response.Write( oLkup.Error & "</p>" )
Response.end
end if
Response.Write( "<p>Pinging " & sHost & "<br>" )
for i = 1 to 3
lRTT = oIcmp.Ping( lAddr )
Response.Write( i & ": " )
if lRTT >= 0 then
Response.Write( lRTT & "<br>" )
else
Response.Write( "Error: " )
Response.Write( oIcmp.Error & "<br>" )
end if
next
Response.Write( "</p>" )
%>
</BODY>
</HTML>
Visual C++ 5.0
// Simple ping example
#include <windows.h>
#include <iostream>
#include <string>
#import "HexIcmp.dll"
#import "HexLookup.dll"
using namespace std;
using namespace HexIcmpLib;
using namespace HexLookupLib;
void main()
{
CoInitialize( NULL );
{
IHexIcmpSyncPtr pIcmp( __uuidof( HexIcmp ) );
IHexLookupSyncPtr pLkup( __uuidof( HexLookup ) );
string sHost = "www.ibm.com";
long lAddr = pLkup->LookUp( sHost.c_str() );
if( 0 == lAddr )
cout << "Lookup of " << sHost
<< " failed." << endl;
else
{
cout << "Pinging " << sHost << "... ";
long lRtt = pIcmp->Ping( lAddr );
if( 0 > lRtt )
cout << "No response" << endl;
else
cout << "RTT = " << lRtt
<< " ms" << endl;
}
}
CoUninitialize();
}
|