Autor Beitrag
alias5000
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: Sa 10.03.07 01:28 
Hi!
Ich verwende in meinem Netzwerkchat folgende Funktion, um alle IP Adressen von allen lokal installierten Netzwerkadaptern zu bekommen (Quelle: Swissdelphicenter):
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:
29:
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;


Dabei ist es nicht ausreichend, einfach localhost, oder 127.0.0.1 zu verwenden, da ich die Computer per IP unterscheiden können muss und dabei mein eigener PC natürlich auch nur einer sein darf.
Ich muss also z.B. UDP- Broadcasts, die auf einem anderen Netzwerkadapter wieder reinkommen, überprüfen können, ob ich das selbst losgeschickt habe.

Bisher hat das auch gut funktioniert.
Jetzt habe ich das mal auf folgendem System getestet:
Windows ME
Kabelgebundenes Ethernet, Verbindung zum Router, IP automatisch beziehen (war wahrscheinlich 192.168.0.92)
aktiviertes WLAN zum selben Router, feste IP: 192.168.0.152

Meine Funktion spuckte mir aber nur 127.0.0.1 aus, was mir in dem Fall nichts bringt, da 192.168.0.95 und 192.168.0.152 mindestens hätten kommen sollen.

Gruß
alias5000

_________________
Programmers never die, they just GOSUB without RETURN
hathor
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 10.03.07 09:41 
Schau mal hier - ist mit Sourcecode:

www.delphi.int.ru/fi...n/nettrafmonitor.zip
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: So 11.03.07 00:00 
Moin!

Haste mal diese Funktionen hier probiert? ;) Als Hostname Leerstring übergeben.

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
alias5000 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2145

WinXP Prof SP2, Ubuntu 9.04
C/C++(Code::Blocks, VS.NET),A51(Keil),Object Pascal(D2005PE, Turbo Delphi Explorer) C# (VS 2008 Express)
BeitragVerfasst: So 11.03.07 00:07 
hm. Also ich kämpfe gerade noch mit dem ersten Vorschlag. Der hat mir auf allen Rechnern schonmal richtige Ergebnisse gebracht :D Die Umsetzung in mein Programm hakelt noch ein wenig.
Deine Routine baut ja eigentlich wie meine auf GetHostByName auf, aber ist ein wenig komplexer, wie es beim ersten Überfliegen scheint.
Ich werds auf jeden Fall mal testen.
Aber jetzt erstmal gute Nacht ;)

Gruß
alias5000

_________________
Programmers never die, they just GOSUB without RETURN