Indy IdICMPClient com laço FOR
Boa tarde pessoal, já estou há dias pesquisando na internet mas me sinto correndo atrás do próprio rabo, preciso verificar em uma rede /24 quais ips estão ativos e depois tratar os ips.
Meu problema é o seguinte: sempre que uso laço FOR para alimentar o idICMPclient.host ele me retorna o erro
Este foi o código que testei no delphi tokyo.
E no botão:
Por favor, me ajudem a solucionar isso. Não posso usar softwares de 3º por precisar desses dados dentro da minha aplicação.
Meu problema é o seguinte: sempre que uso laço FOR para alimentar o idICMPclient.host ele me retorna o erro
10040 message too long
. Como posso fazer para verificar, dentre as 254 possibilidades, quem está ativo?Este foi o código que testei no delphi tokyo.
function TForm1.PingaIP(IP: String): boolean; begin with IdIcmpClient1 do begin Host := IP; ReceiveTimeout := 500; Ping; if ReplyStatus.BytesReceived > 0 then result := true else result := false; end; end;
E no botão:
procedure TForm1.Button1Click(Sender: TObject);
Var
i: integer;
begin
for I := 1 to 254 do
begin
if PingaIP('192.168.0.'+inttostr(i)) = True then
Memo1.lines.add('192.168.0.'+inttostr(i));
end;
end;Por favor, me ajudem a solucionar isso. Não posso usar softwares de 3º por precisar desses dados dentro da minha aplicação.
Jean Ribeiro
Curtidas 0
Melhor post
Emerson Nascimento
20/06/2021
código completo:
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent,
IdComponent, IdRawBase, IdRawClient, IdIcmpClient, IdGlobal;
type
TForm3 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
CancelaPing: boolean;
function PingaIP(strIP: string): boolean;
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
function TForm3.PingaIP(strIP: string): boolean;
var
ICMP : TIdIcmpClient;
ABuffer: String;
begin
ICMP := TIdIcmpClient.Create(nil); // crio o componente em tempo de execução
try
try
ICMP.PacketSize := 32;
ICMP.Host := strIP;
ICMP.ReceiveTimeout := 500;
ICMP.Protocol := 1;
ICMP.IPVersion := Id_IPv4;
ABuffer := ICMP.Host + StringOfChar(' ', 255);
ICMP.Ping(ABuffer); // envio um conteúdo para o ping
if ICMP.ReplyStatus.BytesReceived > 0 then
Result := True
else
Result := False;
except
Result := False;
end;
finally
ICMP.Destroy;
end;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
i: integer;
baseIP, IP: string;
begin
TWinControl(Sender).Enabled := False;
Memo1.Lines.Clear;
baseIP := Edit1.Text;
CancelaPing := False;
for I := 0 to 254 do
begin
IP := baseIP+inttostr(i);
if PingaIP(IP) then
Memo1.Lines.Add(IP + ': Ok')
else
Memo1.Lines.Add(IP + ': Falha');
Application.ProcessMessages;
if CancelaPing then
break;
end;
TWinControl(Sender).Enabled := True;
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
CancelaPing := True;
end;
end.
GOSTEI 1
Mais Respostas
Wanderson Cardoso
18/06/2021
Alguém sabe com faço para trazer os dados de uma planilha Excel para um DBGrid?
Já pesquisei muito só que até agora não achei uma solução!
Será que alguém pode me ajudar ?
Desde já agradeço!
Já pesquisei muito só que até agora não achei uma solução!
Será que alguém pode me ajudar ?
Desde já agradeço!
GOSTEI 0
Jean Ribeiro
18/06/2021
código completo:
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, IdBaseComponent,
IdComponent, IdRawBase, IdRawClient, IdIcmpClient, IdGlobal;
type
TForm3 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Memo1: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
CancelaPing: boolean;
function PingaIP(strIP: string): boolean;
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
function TForm3.PingaIP(strIP: string): boolean;
var
ICMP : TIdIcmpClient;
ABuffer: String;
begin
ICMP := TIdIcmpClient.Create(nil); // crio o componente em tempo de execução
try
try
ICMP.PacketSize := 32;
ICMP.Host := strIP;
ICMP.ReceiveTimeout := 500;
ICMP.Protocol := 1;
ICMP.IPVersion := Id_IPv4;
ABuffer := ICMP.Host + StringOfChar(' ', 255);
ICMP.Ping(ABuffer); // envio um conteúdo para o ping
if ICMP.ReplyStatus.BytesReceived > 0 then
Result := True
else
Result := False;
except
Result := False;
end;
finally
ICMP.Destroy;
end;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
i: integer;
baseIP, IP: string;
begin
TWinControl(Sender).Enabled := False;
Memo1.Lines.Clear;
baseIP := Edit1.Text;
CancelaPing := False;
for I := 0 to 254 do
begin
IP := baseIP+inttostr(i);
if PingaIP(IP) then
Memo1.Lines.Add(IP + ': Ok')
else
Memo1.Lines.Add(IP + ': Falha');
Application.ProcessMessages;
if CancelaPing then
break;
end;
TWinControl(Sender).Enabled := True;
end;
procedure TForm3.Button2Click(Sender: TObject);
begin
CancelaPing := True;
end;
end.
Perfeito, simplesmente perfeito.
GOSTEI 0