AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Delphi IP über Delphi bestimmen!
Thema durchsuchen
Ansicht
Themen-Optionen

IP über Delphi bestimmen!

Ein Thema von wursthunter · begonnen am 20. Jul 2006 · letzter Beitrag vom 20. Jul 2006
 
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.785 Beiträge
 
Delphi 10.4 Sydney
 
#2

Re: IP über Delphi bestimmen!

  Alt 20. Jul 2006, 10:48
Kannst es ja mal damit versuchen.

Grüße
Klaus

Delphi-Quellcode:
function HostNameToIP(HostName: string): u_long;
  var
    RemoteHost: PHostEnt;
  begin
    result := u_long(INADDR_NONE);
    if HostName <> 'then
    try
      result := inet_addr(PChar(HostName)); // try a xxx.xxx.xxx.xxx first
      if result = u_long(INADDR_NONE) then
      begin
        RemoteHost := GetHostByName(PChar(HostName));
        if not ((RemoteHost = NIL) or (RemoteHost^.h_length <= 0)) then
          result := u_long(pointer(RemoteHost^.h_addr_list^)^);
      end;
    except
      result := u_long(INADDR_NONE);
    end;
  end;


  function OwnHostName: string;
  var
    buf : pointer;
    RemoteHost: PHostEnt;
  begin
    result := '';
    buf := NIL;
    try
      getmem(buf, 255);
      GetHostName(buf, 255);
      if char(buf^) <> #0 then
      begin
        RemoteHost := GetHostByName(buf);
        if RemoteHost <> NIL then result := RemoteHost^.h_name
                             else result := '127.0.0.1';
      end else result := '127.0.0.1';
    finally
      if buf <> NIL then FreeMem(buf, 255);
    end;
  end;


  function OwnIPAddress: u_long;
  begin
    result := HostNameToIP(OwnHostName);
  end;
oder hiermit:

Delphi-Quellcode:
function GetLocalIPs: String;
type PPInAddr= ^PInAddr;
var
  wsaData : TWSAData;
  HostInfo : PHostEnt;
  HostName : Array[0..255] of Char;
  Addr : PPInAddr;
begin
  Result:='';
  if WSAStartup($0102, wsaData) <> 0 then
    Exit;
  try
    if GetHostName(HostName, SizeOf(HostName)) <> 0 then
      Exit;
    HostInfo:= GetHostByName(HostName);
    if HostInfo=nil then
      Exit;
    Addr:=Pointer(HostInfo^.h_addr_list);
    if (Addr=nil) or (Addr^=nil) then
      Exit;
    Result:=StrPas(inet_ntoa(Addr^^));
    inc(Addr);
    while Addr^ <> nil do begin
      Result:=Result+^M^J+StrPas(inet_ntoa(Addr^^));
      inc(Addr);
    end;
  finally
    WSACleanup;
  end;
end;
Klaus
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 11:15 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz