Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

what's my INTERNET IP ?

Posted on 2000-04-21
4
265 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
select query - oracle 16 100
Error E2158 compiling with Delphi XE10 Seattle 2 112
Delphi: Connect to running MS Outlook 4 118
Firemonkey DbLookupComboBox equivalent ? 2 54
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

839 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