Beranda > Delphi > # Getting your local IP address or host name.

# Getting your local IP address or host name.

Use this function to get your local IP address or host name.uses Winsock;

type
  IP_HostName = (_IP, _HOSTNAME);

function GetLocalIPAddressOrHostName(IP_Or_HostName: IP_HostName): string;
var
  p : PHostEnt;
  s : array[0..128] of char;
  p2 : pchar;
  wVersionRequested : WORD;
  wsaData : TWSAData;
begin
  {Start up WinSock}
  wVersionRequested := MAKEWORD(1, 1);
  WSAStartup(wVersionRequested, wsaData);
  {Get the computer name}
  GetHostName(@s, 128);
  p := GetHostByName(@s);
  if IP_Or_HostName = _HOSTNAME then
    Result := p^.h_Name
  else
    begin
      {Get the IpAddress}
      p2 := iNet_ntoa(PInAddr(p^.h_addr_list^)^);
      Result := p2;
    end;
  {Shut down WinSock}
  WSACleanup;
end;

Iklan
Kategori:Delphi
  1. Belum ada komentar.
  1. No trackbacks yet.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: