Einzelnen Beitrag anzeigen

RSF

Registriert seit: 13. Mär 2008
150 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#10

AW: Eigene IP Adresse ermitteln

  Alt 10. Feb 2016, 19:54
Ich hatte einmal ein ähnliches Tool benötigt.
1. Lösung war eine einfache .bat Datei wo die IP in eine txt gespeichert wird.
ip.bat
Code:
@echo off & setlocal
REM set URL=http://checkip.dyndns.com/
set URL=http://meineip.softwareschuhmann.de
echo externe IP-Adresse wird ber %URL% ermittelt
echo und in die Datei IP.TXT gespeichert.
set G=%temp%\GetHTML.vbs
echo On Error Resume Next:Set Http=CreateObject("WinHttp.WinHttpRequest.5.1"):Http.Open "GET",WScript.Arguments(0),False:Http.Send:Q=Split(Http.ResponseText,":")(1):WScript.Echo Trim(Split(Q,"<")(0))>%G%
set ExtIP=
for /f %%i in ('cscript //nologo %G% "%URL%"') do set "ExtIP=%%i"
del %G%
if not defined ExtIP echo Externe IP konnte nicht ermittelt werden. & goto :eof
set PFAD=%~dp0
set DATEI=IP.txt
if exist %PFAD%%DATEI%  del /Q %PFAD%%DATEI% 
if not exist %PFAD%%DATEI%  echo %ExtIP%  > %PFAD%%DATEI%
echo ext. IP : %ExtIP%
2. Tool war notwendig um die DynDNS bei auf eigene Strato Seiten zu aktualisieren.

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, winsock, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleCtrls, SHDocVw, StdCtrls, IdBaseComponent, IdComponent,
  IdTCPConnection, IdTCPClient, IdHTTP;

type
  TForm1 = class(TForm)
    btn1: TButton;
    Label1: TLabel;
    IdHTTP1: TIdHTTP;
    Label2: TLabel;
    IdHTTP2: TIdHTTP;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;

    procedure btn1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);


  private
    { Private-Deklarationen }

  public
    { Public-Deklarationen }


  end;

var
  Form1: TForm1;
  IPADRESSE:String;

const
  HOSTNAMEN='xxxx.xxxxxx.de';
  USERNAME ='xxxxxxxxxx';
  PASSWORT ='**********';


implementation

{$R *.dfm}



Function GeExtIP: string;
 var ndx: integer;

 begin
  //result:=uppercase(Form1.IdHTTP1.Get('http://checkip.dyndns.com'));
    result:=uppercase(Form1.IdHTTP1.Get('http://meineip.softwareschuhmann.de'));
    if result='then result:='GET failedelse
    begin
      ndx:=pos(':',result);
      if ndx=0 then result:='host not foundelse
        begin
           delete(result,1,ndx);
           delete(result,pos('<',result),Length(result));
           result:=trim(result);
        end;
      end;

 end;

Function UpdateIP: string; // für Strato
 begin
  Form1.IdHTTP2.Request.BasicAuthentication:=True;
  Form1.IdHTTP2.Request.Username:=USERNAME;
  Form1.IdHTTP2.Request.Password:=PASSWORT;
  result:=Form1.IdHTTP2.Get(Format('http://dyndns.strato.com'
  +'/nic/update?system=dyndns&hostname=%s&myip=%s'
  ,[HOSTNAMEN,IPADRESSE]));

 end;



procedure TForm1.btn1Click(Sender: TObject);
begin
 IPADRESSE:=GeExtIP;
 label1.Caption:= IPADRESSE;
 Label2.Caption:=UpdateIP;

end;

procedure TForm1.FormShow(Sender: TObject);
begin
 Label5.Caption:= HOSTNAMEN;
 btn1click(self);
end;

end.
vielleicht kann das jemand weiterverwenden.
Ronald
  Mit Zitat antworten Zitat