Link to home
Start Free TrialLog in
Avatar of jlislo
jlislo

asked on

How to get ip address?

How to find out
1. IP Address of current PC
2. Name of the PC

Thanks
Avatar of rwilson032697
rwilson032697

From the UDDF:

function my_ip_address:longint;
const
  bufsize=255;
var
  buf: pointer;
  RemoteHost : PHostEnt; (* No, don't free it! *)
begin
  buf:=NIL;
  try
    getmem(buf,bufsize);
    winsock.gethostname(buf,bufsize);   (* this one maybe without domain *)
    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^)^);
  finally
    if buf<>NIL then  freemem(buf,bufsize);
    end;
  result:=winsock.ntohl(result);
  end;

Cheers,

Raymond.
ASKER CERTIFIED SOLUTION
Avatar of rwilson032697
rwilson032697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jlislo

ASKER

Thanks
Avatar of jlislo

ASKER

PHostEnt

What is this?

I'd use the MAX address example, the UDDF one is for Delphi 1...

Cheers,

Raymond.
Avatar of jlislo

ASKER

Max sample give me only the last set of my pc's ip address. How can I get the first three set.

I post another question for gateway ip and host ip, if you know the answer feel free to get the points.

Thanks
So it is... PHostEnt is defined in WinSock in D4 - the code should work in D4...

Cheers,

Raymond.