Autor Beitrag
Fabian W.
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 22.08.05 16:41 
Hallo,

ich hab im Forum nach IP-Adresse gesucht, aber ständig die Frage wie ich meine Ip rausfinde. Ich möchte nun aber die Ip-Adreese zb. von www.delphi-forum.de rausfinden. Wie geht das?
Grendel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 443

Gentoo Linux, MacOS X, Win 2000
D5 Ent, D7 Ent, Lazarus, Anjuta, MonoDevelop
BeitragVerfasst: Mo 22.08.05 16:54 
gethostbyname() sollte weiterhelfen.

Bis neulich ...
Fabian W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 22.08.05 16:56 
Zitat:
[Fehler] Unit1.pas(28): E2003 Undefinierter Bezeichner: 'gethostbyname'

D2005
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Mo 22.08.05 17:00 
VLt. braucht man dazu ne Kompo wie zb Indy?^^
Grendel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 443

Gentoo Linux, MacOS X, Win 2000
D5 Ent, D7 Ent, Lazarus, Anjuta, MonoDevelop
BeitragVerfasst: Mo 22.08.05 17:09 
gethostbyname ist in winsock deklariert.

Wenn Du allerdings mit .NET arbeitest kannst Du über iirc System.DNS die IP ermitteln. Weiß den Funktionsnamen gerade nicht auswendig. Müsste ggf. nachher zu hause mal gucken.

Bis neulich ...
Fabian W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 22.08.05 17:38 
Zitat:
VLt. braucht man dazu ne Kompo wie zb Indy?^^
:lol:

Nun will ich das Ergebniss in nem Label ausgeben, der Rückgabewert ist aber
Zitat:
[Fehler] Unit1.pas(29): E2010 Inkompatible Typen: 'string' und 'PHostEnt'

Vorschläge?
matze.de
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 576

Win95, Win98 SE, WinXp Prof SP2
D7P, D8P, FPC2.0
BeitragVerfasst: Mo 22.08.05 18:04 
Mehr zu der Funktion unter msdn.microsoft.com/l.../gethostbyname_2.asp

mfg matze

_________________
si tacuisses, philosophus mansisses.
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 22.08.05 18:08 
im code von Suche in: Delphi-Forum, Delphi-Library API PING ist ne fertige funktion
darfst du benutzen :P

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
Fabian W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Mo 22.08.05 18:16 
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, winsock;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    function GetIPAddress(const HostName: string): string;
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TFrom1.GetIPAddress(const HostName: string): string;
// from JCL
var
  R: Integer;
  WSAData: TWSAData;
  HostEnt: PHostEnt;
  Host: string;
  SockAddr: TSockAddrIn;
begin
  Result := '';
  R := WSAStartup($0101, WSAData);
  if R = 0 then
    try
      Host := HostName;
      if Host = '' then
      begin
        SetLength(Host, MAX_PATH);
        GetHostName(@Host[1], MAX_PATH);
      end;
      HostEnt := GetHostByName(@Host[1]);
      if HostEnt <> nil then
      begin
        SockAddr.sin_addr.S_addr := Longint(PLongint(HostEnt^.h_addr_list^)^);
        Result := inet_ntoa(SockAddr.sin_addr);
      end;
    finally
      WSACleanup;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := GetIpAddress('web.de');
end;

end.

Heut steh ich echt auf der Leitung, wo liegt der Fehler?

Zitat:

[Fehler] Unit1.pas(9): E2029 Bezeichner erwartet, aber ';' gefunden
[Fehler] Unit1.pas(30): E2023 Funktion benötigt Ergebnistyp
[Fehler] Unit1.pas(16): E2065 Ungenügende Forward- oder External-Deklaration: 'TForm1.GetIPAddress'
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 22.08.05 18:21 
TFrom1

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
Fabian W. Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1766

Win 7
D7 PE
BeitragVerfasst: Di 23.08.05 08:39 
:autsch: :motz: :autsch: :motz: :autsch: :motz: :autsch: :motz: :autsch: :motz:
Danke.