Hallo,
hatte das selbe Problem...
So gehts:
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:
| uses WinSock;
function GetIpAddressByName(const Lines:TStrings; const AHost: String): Boolean;
type PPInAddr= ^PInAddr;
var WSA: TWSAData; HostInfo: PHostEnt; Addr: PPInAddr;
begin Result:=False; if WSAStartUp($101, WSA) = 0 then begin try HostInfo:= getHostByName(PChar(AHost)); Result:=HostInfo<>nil; if Result then begin Addr:=Pointer(HostInfo^.h_addr_list); if (Addr<>nil) AND (Addr^<>nil) then begin Repeat Lines.Add(StrPas(inet_ntoa(Addr^^)) ) ; inc(Addr); Until Addr^=nil; end; end; finally WSACleanup; end; end; end; |
Und dan einfach einbinden...
Delphi-Quelltext
1:
| GetIpAddressByName(Listbox1.Items, 'www.google.de'); |
Interesant ist noch das die Funktion True zurück gibt, falls der Aufruf von getHostByName erfolgreich war, also :
Delphi-Quelltext
1: 2: 3: 4: 5: 6:
| begin if GetIpAddressByName(Listbox1.Items, 'www.google.de') then Showmessage('OK') else ShowMessage('Fehler'); end; |
MfG
Basti
Moderiert von
raziel: Quote- durch Delphi-Tags ersetzt