• Bem vindo à nossa comunidade - Quer se juntar ao resto dos nossos membros? Registre-se*Registros aprovados pela adminitração

[Tutorial] Pegar IP de um site

XSystemX

Usuário XPZ
Adicione: 1 Edit
1 Memo
2 Buttons


Acrecente a seguinte uses: Winsock

Adicione as seguintes functions:
 


Function nibzxd(strIPAddress : String) : String;
Var
strHost : String ;
pszIPAddress : PChar;
pReturnedHostEnt : PHostEnt;
InternetAddr : u_long;
GInitData : TWSADATA;
Begin
strHost := '';
If WSAStartup($101, GInitData) = 0 then
Begin
pszIPAddress := StrAlloc( Length( strIPAddress ) + 1 );
StrPCopy( pszIPAddress, strIPAddress );
InternetAddr := Inet_Addr(pszIPAddress);
StrDispose( pszIPAddress );
pReturnedHostEnt := GetHostByAddr( PChar(@InternetAddr),4, PF_INET );
try
strHost := pReturnedHostEnt^.h_name;
WSACleanup;
Result := strHost
except
Result := 'Host inválido ou não encontrado';
end;
end;
end;

Function clubeprogramacao(WebHostName:string):string;
var
WSAData: TWSAData;
HostEnt: PHostEnt;
begin
WSAStartup(2, WSAData);
//Gethostname(PChar(WebHostName), 255);
//SetLength(WebHostName, StrLen(PChar(WebHostName)));
HostEnt := gethostbyname(PChar(WebHostName));
with HostEnt^ do
begin
Result := Format('%d.%d.%d.%d',
[Byte(h_addr^[0]),Byte(h_addr^[1]),
Byte(h_addr^[2]),Byte(h_addr^[3])]);
end;
WSACleanup;
end;

No event OnClick do button1 adicione:
 


memo1.Lines.Add(edit1.Text+' - '+clubeprogramacao(edit1.Text));

no event OnClick do button2 adicione:

memo1.Clear;

no event OnKeyPress do edit1 adicione:
 


if key=#13 then
begin
button1.Click;
edit1.Clear;
edit1.SetFocus;
end;


Pronto digite o site no no edit1 e aperte o buton1 e aparecera o IP do site no memo.


 
Topo Bottom