Solved

what's my INTERNET IP ?

Posted on 2000-04-21
4
260 Views
Last Modified: 2010-05-18
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;
0
Comment
Question by:bryan7
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
f15iaf earned 25 total points
ID: 2739553
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,winsock,
  StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    procedure FormClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormClick(Sender: TObject);
var
        cp:pchar;
        m:word;
        n:TWsadata;
        p:dword;
        l:phostent;
        y:pchar;
begin
        p:=30;
        getmem(cp,p);
        m:=MAKEWORD(2,0);
        wsastartup(m,n);
        gethostname(cp,p);
        l:=gethostbyname(cp);
        y:=l.h_addr_list^;
        edit1.text:=inttostr(byte(y[0]))+'.'+inttostr(byte(y[1]))+'.'+inttostr(byte(y[2]))+'.'+inttostr(byte(y[3]));
end;

end.
0
 
LVL 3

Author Comment

by:bryan7
ID: 2809074
forgive my long delay.. I haven't been able to test it yet (gotta test it on NT<>w98 network)
0
 
LVL 15

Expert Comment

by:simonet
ID: 2818564
Cool.. tested on NT Server 4 SP 6 and it works! (D5 SP1 Ent)

Alex
0
 
LVL 3

Author Comment

by:bryan7
ID: 3000690
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now