Link to home
Start Free TrialLog in
Avatar of bryan7
bryan7Flag for Japan

asked on

what's my INTERNET IP ?

this only works when my pc is not in a LAN network..
if I'm on LAN this code gets the LAN IP not the internet IP..
how do I retrieve it ?

function TFunctions.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;
ASKER CERTIFIED SOLUTION
Avatar of f15iaf
f15iaf

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 bryan7

ASKER

forgive my long delay.. I haven't been able to test it yet (gotta test it on NT<>w98 network)
Avatar of simonet
Cool.. tested on NT Server 4 SP 6 and it works! (D5 SP1 Ent)

Alex
Avatar of bryan7

ASKER

Hi f15iaf, sorry I haven't accepted it yet, I couldn't test it until now..
it was autograded with B, so I'll give you some more points.. look in the new questions section

thanks.