View Full Version : حرفه ای: تشخیص اتصال به انترنت با دلفی
mtfa65
چهارشنبه 25 دی 1392, 21:02 عصر
سلام
من برنامه ای با دلفی 7 نوشتم و سورس کدی که نشون بده که آیا سیستم به اینترنت وصل است یا نه رو می خواستم؟
و اینکه سرعت اتصال چقدر است؟
مرسی
Valadi
چهارشنبه 25 دی 1392, 21:18 عصر
براي اتصال به اينترنت از ping مثلا سايت گوگل استفاده كن
mtfa65
چهارشنبه 25 دی 1392, 22:55 عصر
سلام
متاسفانه من در این مورد وارد نیستم اگر ممکن است کدش رو برام بذارین.
ممنون
Valadi
پنج شنبه 26 دی 1392, 12:57 عصر
اين نمونه كد ping
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,IdICMPClient, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function pingIp( host: String): Boolean;
var
IdICMPClient: TIdICMPClient;
begin
try
IdICMPClient := TIdICMPClient.Create( nil );
IdICMPClient.Host := host;
IdICMPClient.ReceiveTimeout := 500;
IdICMPClient.Ping;
result := ( IdICMPClient.ReplyStatus.BytesReceived > 0 );
finally
IdICMPClient.Free;
end
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j1,j2:Integer;
begin
j1:=0;
j2:=0;
for I := 1 to 5 do
begin
if pingIp ('www.google.com')=True then
j1:=j1+1
else
j2:=j2+1;
end;
ShowMessage('j1='+IntToStr(j1)+'j2='+IntToStr(j2)) ;
end;
end.
mtfa65
پنج شنبه 26 دی 1392, 15:47 عصر
اين نمونه كد ping
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,IdICMPClient, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function pingIp( host: String): Boolean;
var
IdICMPClient: TIdICMPClient;
begin
try
IdICMPClient := TIdICMPClient.Create( nil );
IdICMPClient.Host := host;
IdICMPClient.ReceiveTimeout := 500;
IdICMPClient.Ping;
result := ( IdICMPClient.ReplyStatus.BytesReceived > 0 );
finally
IdICMPClient.Free;
end
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i,j1,j2:Integer;
begin
j1:=0;
j2:=0;
for I := 1 to 5 do
begin
if pingIp ('www.google.com')=True then
j1:=j1+1
else
j2:=j2+1;
end;
ShowMessage('j1='+IntToStr(j1)+'j2='+IntToStr(j2)) ;
end;
end.
سلام دوست عزیز
من از کد بالای شما استفاده کردم اما چنین پیغامی رو می ده
115463
لطفا راهنمایی بفرمایید.
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.