Board index » delphi » List of IPs on Computer

List of IPs on Computer

Does anybody know how to get a list of IP address on a given computer?
 

Re:List of IPs on Computer


"Trev" <n...@netrubric.ca> schrieb im Newsbeitrag news:3c5c1b71$1_1@dnews...
Quote
> Does anybody know how to get a list of IP address on a given computer?

uses winsock;

function TFm_Main.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;
    STemp: string;
begin
    STemp := '';
    WSAStartup($101, GInitData);
    Result := '';
    GetHostName(Buffer, SizeOf(Buffer));
    phe :=GetHostByName(buffer);
    if phe = nil then
    begin
       Exit;
    end;
    pptr := PaPInAddr(Phe^.h_addr_list);
    I := 0;
    while pptr^[I] <> nil do
    begin
       if I > 0 then STemp := STemp + char($0d) + char($0a);
       STemp := STemp + StrPas(inet_ntoa(pptr^[I]^));
       Inc(I);
    end;
    WSACleanup;
    Result := Stemp;
end;

The result is a stringlist, you can:
  CBoxLAdressen.Items.Clear;
  CBoxLAdressen.Items.Text    := LocalIP;

hth Ernst

Re:List of IPs on Computer


Thanks!

Quote
"Ernst Gerlach" <ernst.gerl...@epost.de> wrote in message

news:3c5c63ab_2@dnews...
Quote
> "Trev" <n...@netrubric.ca> schrieb im Newsbeitrag

news:3c5c1b71$1_1@dnews...
Quote
> > Does anybody know how to get a list of IP address on a given computer?

> uses winsock;

> function TFm_Main.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;
>     STemp: string;
> begin
>     STemp := '';
>     WSAStartup($101, GInitData);
>     Result := '';
>     GetHostName(Buffer, SizeOf(Buffer));
>     phe :=GetHostByName(buffer);
>     if phe = nil then
>     begin
>        Exit;
>     end;
>     pptr := PaPInAddr(Phe^.h_addr_list);
>     I := 0;
>     while pptr^[I] <> nil do
>     begin
>        if I > 0 then STemp := STemp + char($0d) + char($0a);
>        STemp := STemp + StrPas(inet_ntoa(pptr^[I]^));
>        Inc(I);
>     end;
>     WSACleanup;
>     Result := Stemp;
> end;

> The result is a stringlist, you can:
>   CBoxLAdressen.Items.Clear;
>   CBoxLAdressen.Items.Text    := LocalIP;

> hth Ernst

Re:List of IPs on Computer


Is there a way to get the Name and IP list for the entire Local Network.?

Thanks,
Rick

Re:List of IPs on Computer


Quote
> Is there a way to get the Name and IP list for the entire Local Network.?

Hum, I'm going to give you the easy answer here: Use the
IdnetworkCalculator to get the list of local IP given a network number and
network mask.

The problem, of course, is that getting the network number is no problem
(you can, in fact, use the local machine IP) getting the network mask is
rather problematic: there is no easy way to get it and, when there is a way
that doesn't involve reading and parsing half the registry database, it's
not available on all Iny-supported OS (not counting Linux which seems to be
completely different but nowhere easier).

So, if you find a good, xplateform way to do this, please share it with me
:)

Good luck,
Stephane

Other Threads