Fórum info do usuario #287003
05/07/2005
0
Como pego IP da maquina do usuário através de minha aplicação ... Grto
Paulovitor
Curtir tópico
+ 0
Responder
Posts
05/07/2005
Lucaniasalvatore
Bom dia, Paulo.
Segue um exemplo abaixo:
<---------------------------início do código------------------->
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Winsock, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
//usuário
Function GetUser : string;
Var
buffer : String;
buffsize : DWORD;
Begin
buffsize := 128;
Setlength(buffer,buffsize);
Getusername(Pchar(buffer),buffsize);
result := buffer;
end;
//**********
//nome da máquina
Function pcname:string;
var
arrCompName : Array[0..255] Of Char;
strCompName : String;
CompNameLen : Cardinal;
begin
CompNameLen := MAX_COMPUTERNAME_LENGTH + 1;
If GetComputerName(arrCompName, CompNameLen) Then
Begin
SetLength(strCompName, MAX_COMPUTERNAME_LENGTH + 1);
Result := StrPas(arrCompName);
end;
end;
//ip do usuário
function GetIP: string;
var
ipwsa:TWSAData; p:PHostEnt; s:array[0..128] of char; c:pchar;
begin
wsastartup(257,ipwsa);
GetHostName(@s, 128);
p := GetHostByName(@s);
c := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
Result := String(c);
end;
{$R *.dfm}
//usuário
procedure TForm1.FormCreate(Sender: TObject);
begin
label1.Caption := GetUser;
label2.Caption := pcname;
label3.Caption := GetIP;
end;
end.
<-------------------------fim do código--------------------------->
As funções são essas, agora vai da sua imaginação como utilizá-las.
Boa programação.
Lucania
Segue um exemplo abaixo:
<---------------------------início do código------------------->
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Winsock, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
//usuário
Function GetUser : string;
Var
buffer : String;
buffsize : DWORD;
Begin
buffsize := 128;
Setlength(buffer,buffsize);
Getusername(Pchar(buffer),buffsize);
result := buffer;
end;
//**********
//nome da máquina
Function pcname:string;
var
arrCompName : Array[0..255] Of Char;
strCompName : String;
CompNameLen : Cardinal;
begin
CompNameLen := MAX_COMPUTERNAME_LENGTH + 1;
If GetComputerName(arrCompName, CompNameLen) Then
Begin
SetLength(strCompName, MAX_COMPUTERNAME_LENGTH + 1);
Result := StrPas(arrCompName);
end;
end;
//ip do usuário
function GetIP: string;
var
ipwsa:TWSAData; p:PHostEnt; s:array[0..128] of char; c:pchar;
begin
wsastartup(257,ipwsa);
GetHostName(@s, 128);
p := GetHostByName(@s);
c := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
Result := String(c);
end;
{$R *.dfm}
//usuário
procedure TForm1.FormCreate(Sender: TObject);
begin
label1.Caption := GetUser;
label2.Caption := pcname;
label3.Caption := GetIP;
end;
end.
<-------------------------fim do código--------------------------->
As funções são essas, agora vai da sua imaginação como utilizá-las.
Boa programação.
Lucania
Responder
Gostei + 0
06/07/2005
Paulovitor
LucaniaSalvatore a do IP não ta funcionando !!
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)