{DELPHI 6}pobranie Zewnetrznego Ip a nie z sieci lan

0

jak pobrac swoj ip zewnetrzny jezeli komputer dziala w sieci i jest serwerem dla tej sieci np
adres w sieci lan to 192.168.0.1 a zewnetrzny to 212.211.123.5
tzn jak pobrac ten drogi.
dodam ze:

procedure TForm1.Button1Click(Sender:TObject);
var
p: PHostEnt;
s:array[0..128] of char;
p2:pchar;
begin
GetHostName(@s, 128);
p := GetHostByName(@s);
Memo1.Lines.Add(p.h_Name);
p2 := iNet_ntoa(PInAddr(p
.h_addr_list));
Memo1.Lines.Add(p2);
end;
zwraca mi adres z sieci lan a nie zewnetrzny (nawet jesli jestem polonczony z netem bezpozrednio przez SDI)

0

Ja to robię tak:

  1. Robię na swoim serverze plik PHP wyświetlający ip:
    &ltcode&gt
    if (getenv("HTTP_X_FORWARDED_FOR"))
    { $ip=getenv("HTTP_X_FORWARDED_FOR"); }
    else
    { $ip=getenv("REMOTE_ADDR"); }
    echo("Twój IP to: $ip");
    &lt/code&gt
  2. Sciągam go ;)--
    Tomkiewicz
    [email protected]
    www.wolfenstein-best.prv.pl
0

Ale nie z zadnego php tylko normalnie delphi.

0

Wejdz na www.torry.net i tam masz w dziale bodajże tipsy hmm... przykład, przykład korzysta ze strony www.whatismyiP.com , z resztą ma sz tu przykład listingu do pobierania IP....

{
This code requires a server running a script that generates a web
page that has your IP address in it.
This example uses http://www.whatismyip.com/
The script then searches for the first time
that 'Your ip is ' shows up and then looks for a
correctly formatted IP address from that point.

This works using Delphi 6 Enterprise but should work with previous
versions with little or no modification, I think.
}

unit unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes,
Graphics, Controls, Forms, Dialogs, Psock,
NMHttp, StdCtrls, ExtCtrls, Menus,
Winsock, ComCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
NMHTTP1: TNMHTTP;
Memo1: TMemo;
Edit1: TEdit;
StatusBar1: TStatusBar;
Koniec: TButton;
Zapisz: TButton;
SaveD: TSaveDialog;
procedure Button1Click(Sender: TObject);
procedure Exit1Click(Sender: TObject);
procedure KoniecClick(Sender: TObject);
procedure ZapiszClick(Sender: TObject);
procedure Memo1Change(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses ClipBrd;

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
InetIP: string;
WebAddress, SearchString: string;
Buff, P, FT: PChar;
BuffLen: Word;
StartPos, StringLength, TempInt: Integer;
begin
WebAddress := 'http://www.whatismyip.com/';
SearchString := 'Your ip is ';
Memo1.Clear;
try
NMHTTP1.Get(WebAddress);
except
on E: Exception do
begin
MessageDlg('Nie mogę sprawdzić IP! ' +
'Zobacz czy masz połaczenie z internetem', mtError, [mbOK], 0);
end;
end;
Memo1.Text := NMHTTP1.Body;
Memo1.SelStart := 0;
GetMem(FT, Length(SearchString) + 1);
StrPCopy(FT, SearchString);
BuffLen := Memo1.GetTextLen + 1;
GetMem(Buff, BuffLen);
Memo1.GetTextBuf(Buff, BuffLen);
P := Buff + Memo1.SelStart + Memo1.SelLength;
P := StrPos(P, FT);
if P = nil then MessageBeep(0)
else
begin
Memo1.SelStart := P - Buff;
Memo1.SelLength := Length(SearchString);
end;
StringLength := Memo1.SelLength;
StartPos := Memo1.SelStart + StringLength;
tempint := StartPos;
InetIP := `;
while ((Buff[TempInt] in ['0'..'9']) or
(Buff[TempInt] = '.')) do
begin
InetIP := InetIP + Buff[TempInt];
tempint := tempint + 1;
end;
FreeMem(FT, Length(SearchString) + 1);
FreeMem(Buff, BuffLen);
Edit1.Text := InetIP;
end;

procedure TForm1.Exit1Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.KoniecClick(Sender: TObject);
begin
Application.Terminate;
end;

procedure TForm1.ZapiszClick(Sender: TObject);
begin
if SaveD.Execute then
Memo1.Lines.SaveToFile(SaveD.FileName);
end;

procedure TForm1.Memo1Change(Sender: TObject);
begin
Zapisz.Enabled:=true;
if Memo1.Text&lt&gt` then
Zapisz.Enabled:=true
else
Zapisz.Enabled:=false;
end;

end.

[email protected]
POZDRAWIAM
DELPHI RULEZ
NIECH MOCz BĘDZIE Z WAMI
:-))

1 użytkowników online, w tym zalogowanych: 0, gości: 1