06/05/11 14:59
camaleonteplus
So come si ricava l'IP Locale usando un componente Indy adesso sto cercando di ricavare quello publico usando questo codice trovato in rete, non da errori di compilazioni ma quando clicco sul bottone mi da questo errore:
HTTP/1.1 403 Forbidden
é il codice sbagliato o è il sito usato? li ho utilizzati entrambi ma da sempre lo stesso errore.
HTTP/1.1 403 Forbidden
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls; type TForm1 = class(TForm) IdHTTP1: TIdHTTP; Button1: TButton; function GetPublicIp: String; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function TForm1.GetPublicIp: String; var B, E, I: Integer; Str, SStr, EStr, R: String; IdHTTP1: TIdHTTP; begin Result := ''; B := 0; E := 0; IdHTTP1 := TIdHTTP.Create(nil); try //Str := IdHTTP1.Get('http://www.whatismyip.com/'); Str := IdHTTP1.Get('http://www.ip-adress.com/'); finally FreeAndNil(IdHTTP1); end; if B=0 then begin SStr := 'Your IP Is '; B := Pos(SStr, Str); end; if B=0 then begin SStr := 'Your IP - '; B := Pos(SStr, Str); end; if B=0 then begin SStr := 'My IP address: '; B := Pos(SStr, Str); end; if B=0 then raise Exception.Create('Stringa non trovata! ('+SStr+')'); if E=0 then begin EStr := 'WhatIsMyIP'; //E := Pos(EStr, Str); E := B+16+Length(SStr); end; if E=0 then raise Exception.Create('Stringa non trovata! ('+EStr+')'); Result := ''; R := Copy(Str, B+Length(SStr), E-B-Length(SStr)-1); for I := 1 to Length(R) do if Pos(R[I], '0123456789.')>0 then Result := Result+R[I]; end; procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage(GetPublicIp); end; end.
é il codice sbagliato o è il sito usato? li ho utilizzati entrambi ma da sempre lo stesso errore.
aaa