Autor Beitrag
freq.9
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39

Win XP (RedHat 9)
Delphi 7.0 Ent
BeitragVerfasst: Mi 14.04.04 10:46 
Wie bekomm ich die Lokale IP heraus? Hab auf Delphi-Treff.de was gefunden aber das hilft mir nicht weil ich da keine IP ausgegeben bekomme.
Hier der Code von www.delphi-treff.de
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:
26:
27:
28:
uses WinSock;

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;

_________________
Admin of RealScripts


Zuletzt bearbeitet von freq.9 am Mi 14.04.04 10:51, insgesamt 1-mal bearbeitet
ixtreme
Gast
Erhaltene Danke: 1



BeitragVerfasst: Mi 14.04.04 10:50 
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 GetIP: 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;




procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Text := GetIP;
end;
freq.9 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 39

Win XP (RedHat 9)
Delphi 7.0 Ent
BeitragVerfasst: Mi 14.04.04 10:53 
Jau danke funzt perfekt. Wieso bin ich nicht selbst drauf gekommen *ouch*. Naja bin ja auch noch ned sooooo der Held in Delphi

_________________
Admin of RealScripts