Solved

what's my INTERNET IP ?

Posted on 2000-04-21
4
269 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
[X]
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
  • 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month7 days, 1 hour left to enroll

622 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