Board index » delphi » Get current IP address and hostname?

Get current IP address and hostname?

Is there a way in Delphi to get the IP address and/or hostname from the
OS?  Is this in the registry somewhere, and if so, where is it
documented?  I searched through the Delphi help (well, okay, I looked in
the index -- the HELP engine bombed after trying for a long time to index
everything, cruddy engine that it is).

Reason:  I need to write a program to run on Win95 (NT would be nice, too)
that would log the IP address and hostname (as well as Netware login name,
but I already have a DOS program to do that :) to a file, so that we can
track IP addresses and hostnames.  There appear to be a couple of
mis-configured machines on our network, and some have changed hands
without having their hostnames changed, so I want to track them the way I
do our DOS/Win 3.x machines.  (I can't use the same program for Win95/NT,
since the IP address isn't in net.cfg and the hostname isn't in
autoexec.bat ;).

Thanks in advance,
Kendall :)

--
Kendall P. Bullen                   Web: http://www.his.com/~kendall/
                                 E-mail: kendall@-->^^^^^^^

 

Re:Get current IP address and hostname?


Hello Kendall,
try the sample source "Detect your own IP Address" @
http://www.preview.org/q/q2056.shtml

More Delphi snippets at http://www.preview.org/e/help.shtml

Quote
Kendall P. Bullen wrote in message ...
>Is there a way in Delphi to get the IP address and/or hostname from the
>OS?  Is this in the registry somewhere, and if so, where is it

[..]

Re:Get current IP address and hostname?


On Thu, 28 May 1998 00:34:22 -0500, see-my-...@his.com (Kendall P.

Quote
Bullen) wrote:
>Is there a way in Delphi to get the IP address and/or hostname from the
>OS?  Is this in the registry somewhere, and if so, where is it
>documented?  I searched through the Delphi help (well, okay, I looked in
>the index -- the HELP engine bombed after trying for a long time to index
>everything, cruddy engine that it is).

>Reason:  I need to write a program to run on Win95 (NT would be nice, too)
>that would log the IP address and hostname (as well as Netware login name,
>but I already have a DOS program to do that :) to a file, so that we can
>track IP addresses and hostnames.  There appear to be a couple of
>mis-configured machines on our network, and some have changed hands
>without having their hostnames changed, so I want to track them the way I
>do our DOS/Win 3.x machines.  (I can't use the same program for Win95/NT,
>since the IP address isn't in net.cfg and the hostname isn't in
>autoexec.bat ;).

>Thanks in advance,
>Kendall :)

Hello Kendall

This little function will get you the IP address and hostname via
winsock; works on 95, 98 & NT.

function LocalIP : string;
type
  TaPInAddr = array [0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
var
  phe  : PHostEnt;
  pptr : PaPInAddr;
  Buffer : array [0..63] of char;
  I    : Integer;
  GInitData      : TWSADATA;
begin
  WSAStartup($101, GInitData);
  Result := '';
  GetHostName(Buffer, SizeOf(Buffer));
  phe :=GetHostByName(buffer);
  if phe = nil then Exit;
  pptr := PaPInAddr(Phe^.h_addr_list);
  I := 0;
  while pptr^[I] <> nil do begin
    result:=StrPas(inet_ntoa(pptr^[I]^));
    Inc(I);
  end;
  WSACleanup;
end;

Enjoy,

Mark Cummins
Cape Town, South Africa
EMail: g...@iafrica.com

"Try to relax and enjoy the crisis."
    -- Ashleigh Brilliant

Re:Get current IP address and hostname?


Heya,

Quote
In article <356dfdd2.858...@news.iafrica.com>, g...@iafrica.com wrote:
>This little function will get you the IP address and hostname via
>winsock; works on 95, 98 & NT.

You da man!  :-)  Thanks a bunch!  I'll try it out ASAP.

Cheers!

--
Kendall P. Bullen                   Web: http://www.his.com/~kendall/
                                 E-mail: kendall@-->^^^^^^^

Re:Get current IP address and hostname?


In article <P_6b1.54$Db3.123...@proxye1.san.rr.com>, "Mary Lou Alcove"

Quote
<malco...@san.rr.com> wrote:
>try the sample source "Detect your own IP Address" @
>http://www.preview.org/q/q2056.shtml

>More Delphi snippets at http://www.preview.org/e/help.shtml

Woo-hoo!  Thanks a bunch, I'll check 'em both out!  :-)

Cheers!

--
Kendall P. Bullen                   Web: http://www.his.com/~kendall/
                                 E-mail: kendall@-->^^^^^^^

Re:Get current IP address and hostname?


Hi Kendall!
Despite you have already solution for your question, here is another:
Take a look at the TTCP component. Look at the properties. There you find IP
and HostName (I don't remember exact names, something like IPList or LocalIP
and HostName). If you are using ICS from Francois Piette, use LocalIPList
and LocalHost functions.

Greetingz,

JG

Kendall P. Bullen D??? ???Y?? ...

Quote
>Is there a way in Delphi to get the IP address and/or hostname from the
>OS?  Is this in the registry somewhere, and if so, where is it
>documented?  I searched through the Delphi help (well, okay, I looked in
>the index -- the HELP engine bombed after trying for a long time to index
>everything, cruddy engine that it is).

>Reason:  I need to write a program to run on Win95 (NT would be nice, too)
>that would log the IP address and hostname (as well as Netware login name,
>but I already have a DOS program to do that :) to a file, so that we can
>track IP addresses and hostnames.  There appear to be a couple of
>mis-configured machines on our network, and some have changed hands
>without having their hostnames changed, so I want to track them the way I
>do our DOS/Win 3.x machines.  (I can't use the same program for Win95/NT,
>since the IP address isn't in net.cfg and the hostname isn't in
>autoexec.bat ;).

>Thanks in advance,
>Kendall :)

>--
>Kendall P. Bullen                   Web: http://www.his.com/~kendall/
>                                 E-mail: kendall@-->^^^^^^^

Other Threads