ICMP Component - Samples (Using in C#)
Using OstroSoft ICMP Component (OSICMP.dll) in Visual Basic.NET
Download project source code

Minimum requirements: C#, OSICMP.dll*
* If you don't have OstroSoft ICMP Component, see installation instructions

1. In Visual Studio.NET create new C# Windows Application
2. Click on Project menu and select "Add Reference".
3. In "Add Reference" dialog box click on COM tab and select OSICMP. Click OK to save a new reference.
3. Enter the following code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace using_csharp
{
public class frmPing : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtHost;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox txtOutput;
private System.Windows.Forms.Button cmdPing;
private System.ComponentModel.Container components = null;
public frmPing()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code //supressed
[STAThread]
static void Main()
{
Application.Run(new frmPing());
}
private void cmdPing_Click(object sender, System.EventArgs e)
{
OSICMP.PingClass oPing = new OSICMP.PingClass();
String s = "";
try
{
for (int i = 0; i < 4; i++)
{
oPing.Send(txtHost.Text, 1000, 32);
if (i == 0)
{
if (txtHost.Text != oPing.IP)
s = txtHost.Text + " [" + oPing.IP + "]";
else
s = txtHost.Text;
txtOutput.Text = "Pinging " + s + " with " +
oPing.PacketSize + " bytes of data:\r\n\r\n";
}
txtOutput.Text = txtOutput.Text + "Reply from " +
oPing.IP + ": bytes=" + oPing.PacketSize + " time=" +
oPing.RoundTripTime + "ms TTL=" + oPing.TTL + "\r\n";
oPing.Sleep(1000);
}
txtOutput.Text = txtOutput.Text + "\r\ncomplete";
}
catch (Exception ex)
{
txtOutput.Text = "Error: " + ex.Message;
}
}
}
}
|