Autor Beitrag
WolfB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 39

WinXP Professional
Delphi 7
BeitragVerfasst: Fr 24.02.06 22:20 
hi, mal ne frage,
kann man mit delphi sich die ip eines rechners, also des rechners, auf dem das programm läuft, rausfinden und diese ausgeben lassen?
recall
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 449



BeitragVerfasst: Fr 24.02.06 22:31 
hi,

welche IP möchtest du denn haben ?
Die im lokalen Netzwerk, oder die IP, die der Rechner im Internet hat ?
Lokal ist das allerdings ggf. nicht eindeutig (mehrere Netzwerkkarten), es gibt dazu aber
Methoden (suche im Delphi-forum, ich weiß nicht mehr wo genau, aber ich hab das hier schonmal gelesen).

Im Internet kannst du ggf. mit einer HTTP-Komponente (z.B. Indy) ein php-Skript, z.B. www.prodego.de/myIP.php aufrufen und die IP-Adresse auslesen (Das ist jetzt meine persönliche Adresse, es gibt aber auch ein php-Skript bei DynDns, das einem die IP anzeigt).

Viele Grüsse.
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Fr 24.02.06 22:31 
1. Komponente IdIPWatch verwenden
2.
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:
uses Winsock;

function GetLocalIPs(const Lines:TStrings):Boolean;
type
  PPInAddr= ^PInAddr;
var
  wsaData: TWSAData;
  HostInfo: PHostEnt;
  HostName: Array[0..255of Char;
  Addr: PPInAddr;
begin
  Result:=False;
  Lines.Clear;
  if WSAStartup($0102, wsaData)=0 then
  try
    if gethostname(HostName, SizeOf(HostName)) = 0 then Begin
       HostInfo:= gethostbyname(HostName);
       if HostInfo<>nil then Begin
          Addr:=Pointer(HostInfo^.h_addr_list);
          if (Addr<>nilAND (Addr^<>nilthen 
             Repeat
                    Lines.Add(StrPas(inet_ntoa(Addr^^)));
                    inc(Addr);
             Until Addr^=nil;
       end;
    end;
    Result:=True;
  finally
    WSACleanup;
  end;
end;

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Sa 25.02.06 13:48 
Moin!

Mit der Funktion:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
// nur die erste Adresse:
function GetIPByName(const Hostname : String;  
                     var   IPv4     : in_addr  
                     ): Boolean;  
// oder alle Adressen
function GetIPByName(const Hostname : String;  
                     var   IPv4List : in_addr_list  
                     ): Boolean;

aus dieser Unit, Parameter Hostname auf einen Leerstring setzen. :wink:

Im Codebeispiel der Unit im Anhang ist das ganze auch als laufendes Programm "begutachtbar", einfach als Hostnamen "localhost" oder Leerstring eingeben und "nur IP auflösen" anklicken.

cu
Narses