Autor Beitrag
Silas
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: So 27.08.06 09:08 
Wie kann ich über den DNS-Server meines Providers die IP-Adresse eines Computers im Internet aus seinem Hostnamen (z.B. www.delphi-forum.de/) ermitteln - und das ganze in Delphi 3 Pro (ich bin ein unverbesserlicher Nostalgiker ;-))?
Silas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: So 27.08.06 15:46 
*umhilferuf* ;-)
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 27.08.06 23:04 
Moin und :welcome: im Forum!

Schau mal hier, da gibt es die Funktionen GetIPByName, damit geht das. Ist allerdings nicht direkt für D3 geeignet, fürchte ich. Da du aber nur einen Wrapper für GetHostByName der WSA brauchst, solltest du das eigentlich leicht daraus ableiten können.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Silas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: Mo 28.08.06 09:33 
Ich bekomm beim compilieren nur fünf Meter Compilerfehler angezeigt. Mein Delphi ist wahrscheinlich etwas zu vorsintflutlich :oops: . Kannst du mir die Funktion in eine DLL packen, das ich sie trotzem benutzen kann?

Danke!
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mo 28.08.06 09:52 
Ich benutze immer diese, kenne den Autor allerdings nicht !

Sollte auch unter D3 funktionieren:

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:
uses ...,winsock...

function GetIPFromHost (var HostName, IPaddr, WSAErr: string): Boolean;
type
  Name = array[0..100of Char;
  PName = ^Name;
var
  HEnt: pHostEnt;
  HName: PName;
  WSAData: TWSAData; 
  i: Integer; 
begin
  Result := False;
  if WSAStartup($0101, WSAData) <> 0 then begin
    WSAErr := 'Winsock is not responding."'
    Exit;
  end;
  IPaddr := ''
  New(HName);
  if GetHostName(HName^, SizeOf(Name)) = 0 then
  begin
    HostName := StrPas(HName^);
    HEnt := GetHostByName(HName^);
    for i := 0 to HEnt^.h_length - 1 do 
     IPaddr :=
      Concat(IPaddr,
      IntToStr(Ord(HEnt^.h_addr_list^[i])) + '.');
    SetLength(IPaddr, Length(IPaddr) - 1);
    Result := True;
  end
  else begin
   case WSAGetLastError of
    WSANOTINITIALISED:WSAErr:='WSANotInitialised';
    WSAENETDOWN      :WSAErr:='WSAENetDown';
    WSAEINPROGRESS   :WSAErr:='WSAEInProgress'
   end;
  end;
  Dispose(HName);
  WSACleanup;
end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Silas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: Mo 28.08.06 09:57 
Welche Units muss ich für die Funktion einbinden? Mein Compiler kennt einen ganzen Haufen bezeichner nicht.
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mo 28.08.06 09:59 
eigentlich nur die winsock, wie im Beispiel !!

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Silas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: Mo 28.08.06 10:02 
Extrem-Blamage für mich: Ich hab die uses-Zeile übersehn... :oops: :oops:
Vielen Dank für die Funktion!
Silas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: Mo 28.08.06 10:30 
Ich geh mal davon aus, dass ich einfach zu dumm bin, aber ich bekomm grundsätzlich meine eigene IP zurück (nicht die 127.0.0.1, sondern meine IP im Netz), egal welchen Hostnamen ich an die Funktion übergeb.
Ich hab an HostName einen Internetadresse übergeben (z.B. www.delphi-forum.de/), und dann die Adresse aus IPAddr ausgelesen. Die Error-Var war immer leer.
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Mo 28.08.06 12:07 
Das ist auch irgendwie der Sinn der Funktion. Sie holt immer zuerst den eigenen Hostname (GetHostName).
Wenn du statt dieser Zeile den Inhalt von Hostname in die HName-Variable kopierst, sollte es gehen. Dann allerdings auch dafür sorgen, dass Hostname kein var-parameter ist.

Achso, und: Hostnamen haben kein Protokoll, richtig wäre also www.delphi-forum.de (ohne )

HTH,
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
chrisw
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 439
Erhaltene Danke: 3

W2K
D7
BeitragVerfasst: Mo 28.08.06 13:46 
OK, mein Fehler !

Hier hab ich die function mal umgebaut

ausblenden 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:
uses ... winsock..


function GetIPFromHostname (HostName : String): String;
type
  Name =array[0..254of Char;
  PName = ^Name;
var
  HEnt: pHostEnt;
  HName: PName;
  WSAData: TWSAData;
  i: Integer;
begin
  Result := '';
  if WSAStartup($0101, WSAData) <> 0 then Exit;
  New(HName);
  StrPCopy(PChar(HName),HostName);
  HEnt := GetHostByName(HName^);
  for i := 0 to HEnt^.h_length - 1 do
  Result :=
  Concat(Result,IntToStr(Ord(HEnt^.h_addr_list^[i])) + '.');
  SetLength(Result, Length(Result) - 1);
  Dispose(HName);
  WSACleanup;
end;

_________________
Man sollte keine Dummheit zweimal begehen, die Auswahl ist schließlich groß genug.
Silas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 478

Windows XP Home
Delphi 2005, RAD Studio 2007, MASM32, FASM, SharpDevelop 3.0
BeitragVerfasst: Mo 28.08.06 14:41 
Danke, jetzt funktioniert's.

@Matrok: Danke für den Hinweis!