Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    IP Pubblico (Delphi7)

    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
    codice:
    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.

  2. #2
    Ho fatto cosi ma non mi da nessuna IP:
    codice:
    function TForm1.GetPublicIp: String;
        var
          IP: String;
          begin
          IdHttp1.Request.Host:= 'http://www.whatismyip.com';
          IP := IdHttp1.Get('http://www.whatismyip.com/automation/n09230945.asp');
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ShowMessage(GetPublicIp);
    end;

  3. #3
    Risolto in qusto modo:
    codice:
        function TForm1.GetPublicIp: String;
                  begin
              IdHttp1.Request.Host:= 'http://www.whatismyip.com/automation/n09230945.asp';
              result := IdHttp1.Get('http://www.whatismyip.com/automation/n09230945.asp');
        end;
         
        procedure TForm1.Button1Click(Sender: TObject);
        begin
          IPPubblico.Caption:= 'IP Pubblico: ' + (GetPublicIp);
        end;

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.