Fórum Pegar IP e nome de Maquinas na rede #284233

09/06/2005

0

Olá pessoal!
Gostaria de saber como faço para conseguir pegar o IP e o nome da máquina em uma rede.
Exemplo - Tenho uma rede com 3 micros, e gostaria que meu aplicativo me mostrasse todos os que estao na rede seus IP e Nomes.
Por favor pessoal, preciso urgente disso, se puderem me mandar o codigo ou algum componente para isso eu agradeço muito!
Conto com voces!!
Até mais!!


Marcelofeital

Marcelofeital

Responder

Posts

09/06/2005

Renatosilva

Uses Windows, SysUtils, Winsock;

//...

function NetHostName: string;
var
  lpBuffer : PChar;
  nSize : DWord;
const
  Buff_Size = MAX_COMPUTERNAME_LENGTH + 1;
begin
  nSize := Buff_Size;
  lpBuffer := StrAlloc(Buff_Size);
  GetComputerName(lpBuffer,nSize);
  Result := string(lpBuffer);
  StrDispose(lpBuffer);
end;

function NetUserName: string;
var
  lpBuffer : PChar;
  nSize : DWord;
const
  Buff_Size = 100;
begin
  nSize := Buff_Size;
  lpBuffer := StrAlloc(Buff_Size);
  GetUserName(lpBuffer,nSize);
  Result := string(lpBuffer);
  StrDispose(lpBuffer);
end;

function NetHostIP: string;
var
  WSAData: TWSAData;
  HostEnt: PHostEnt;
  Name: string;
begin
  WSAStartup(2, WSAData);
  SetLength(Name, 255);
  Gethostname(PChar(Name), 255);
  SetLength(Name, StrLen(PChar(Name)));
  HostEnt := gethostbyname(PChar(Name));
  with HostEnt^ do
    Result := Format(´¬d.¬d.¬d.¬d´, [Byte(h_addr^[0]),
      Byte(h_addr^[1]), Byte(h_addr^[2]), Byte(h_addr^[3])]);
  WSACleanup;
end;



Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar