How to get ip address?

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

Thanks
jlisloAsked:
Who is Participating?
 
rwilson032697Connect With a Mentor Commented:
Here's another way:

To get the computer name use GetComputerName like this:

var
  s : String;

begin
  SetLength(S, 256)
  GetComputerName(PChar(s), 255);
end;  



For the MAC address (the ID of the network card), use the code below:

function CoCreateGuid(P:Pointer):Integer;stdcall;external 'ole32.dll';

function GetNicAddr:AnsiString;
var
  T:AnsiString;
  I:Integer;
begin
  Result:='';
  SetLength(T,16);
  if CoCreateGUID(@T[1])=S_OK then begin
    for I:=11 to 15 do Result:=Result+IntToStr(Ord(T[I]))+'.';
    Result:=Result+IntToStr(Ord(T[16]));
  end;
end;

the GetNicAddr function will return the information you want.

Cheers,

Raymond.
0
 
rwilson032697Commented:
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.
0
 
jlisloAuthor Commented:
Thanks
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
jlisloAuthor Commented:
PHostEnt

What is this?

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

Cheers,

Raymond.
0
 
jlisloAuthor Commented:
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
0
 
rwilson032697Commented:
So it is... PHostEnt is defined in WinSock in D4 - the code should work in D4...

Cheers,

Raymond.
0
All Courses

From novice to tech pro — start learning today.