Einzelnen Beitrag anzeigen

Benutzerbild von chrisw
chrisw

Registriert seit: 11. Jan 2005
Ort: Schleswig
193 Beiträge
 
Delphi XE8 Professional
 
#5

Re: IP einer URL herausfinden

  Alt 9. Sep 2005, 13:12
Delphi-Quellcode:
uses winsock......;
function GetIPFromHost (var HostName, IPaddr, WSAErr: string): Boolean;
type
  Name = array[0..100] of 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;


procedure TForm1.Button1Click(Sender: TObject);
var a,s,e:string;
begin
  a:= 'www.google.de';
  GetIPFromHost(a,s,e);
  showmessage(s);
end;
Christian Wahl
me, myself and I, die lustigen Drei !!
  Mit Zitat antworten Zitat