Board index » delphi » How to get a computer's IP address

How to get a computer's IP address

How can I get my computer's IP address by
delphi program.

Please reply by e-mail.

Thanks in advance.

 

Re:How to get a computer's IP address


I got this at an earlier time from these forums.

The code is untested.

uses
    WinSock; // type PHostEnt

  function My_IP_Address : longint;
  var
    buf : array [0..255] of char;
    RemoteHost : PHostEnt;
  begin
    winsock.gethostname(@buf, 255);
    RemoteHost:=Winsock.GetHostByName(buf);
    if RemoteHost=NIL then
      my_ip_address:=winsock.htonl($07000001) { 127.0.0.1 }
    else
      my_ip_address:=longint(pointer(RemoteHost^.h_addr_list^)^);
    result:=winsock.ntohl(result);
  end;

Hope that helps!

Rkr

Quote
Brad Jeng wrote:

> How can I get my computer's IP address by
> delphi program.

> Please reply by e-mail.

> Thanks in advance.

--
                   \|||/
                   /'^'\
                  ( 0 0 )
--------------oOOO--(_)--OOOo--------------
. Reid Roman                              .
. Delphi Programmer / Analyst             .
. TVisualBasic:=class(None);              .
. May the Source be With You              .
-------------------------------------------
. Auto-By-Tel (http://www.autobytel.com)  .
. Irvine, CA U.S.A                        .
. E-Mail : rkroman (at) pacbell (dot) net .
. or reidr (at) autobytel (dot) com       .
-------------------------------------------

Other Threads