Social Icons

Pages

Showing posts with label get IP Address. Show all posts
Showing posts with label get IP Address. Show all posts

Get IP Address

Bagaimana untuk mendapatkan alamat IP
Berikut adalah dua metode untuk mendapatkan alamat IP Anda, tambahkan WinSock untuk menggunakan klausa
Uses WinSock

Programnya berikut ini :

function GetIPAddress: Integer;
var
  Buffer: array[0..255] of Char;
  RemoteHost: PHostEnt;
begin
  Winsock.GetHostName(@Buffer, 255);
  RemoteHost := Winsock.GetHostByName(Buffer);
  if RemoteHost = nil then
    Result := winsock.htonl($07000001) { 127.0.0.1 }
  else
    Result := longint(pointer(RemoteHost^.h_addr_list^)^);
    Result := Winsock.ntohl(Result);
end;// function GetIPAddress: Integer;

function GetIPAddressAsString: String;
var
  tempAddress: Integer;
  Buffer: array[0..3] of Byte absolute tempAddress;
begin
  tempAddress := GetIPAddress;
  Result := Format('%d.%d.%d.%d', [Buffer[3], Buffer[2], Buffer[1], Buffer[0]]);
end;// function GetIPAddressAsString: String;
{Memanggil programnya adalah demikian}
procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(GetIPAddressAsString);
end;
 
Blogger Templates