Autor Beitrag
Jagg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Di 21.10.03 13:47 
Hallo Leute !

Wie bekomme ich den Computername lokal oder im Netzwerk raus ???
Ich habe da so einen Befehl "Window.GetComputername",kann aber nix mit anfangen,könnt ihr mir helfen ???

Jagg !!!
barfuesser
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 324



BeitragVerfasst: Di 21.10.03 14:02 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
uses
  Windows;

function getMachineName: String;
var
  Buffer: array [0..MAX_COMPUTERNAME_LENGTH] of Char;
  Size:   Cardinal;
begin
  Size := MAX_COMPUTERNAME_LENGTH + 1;
  GetComputerName(Buffer, Size);
  Result := String(Buffer);
end;


[edit]
Wenn Du Windows nicht einbinden möchtest, kannst du statt der Konstante MAX_COMPUTER_NAME_LENGTH auch die Zahl 15 setzen.
[/edit]

barfuesser


Zuletzt bearbeitet von barfuesser am Di 21.10.03 14:05, insgesamt 1-mal bearbeitet
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Di 21.10.03 14:04 
danke und wie geht das im netzwerk ?
barfuesser
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 324



BeitragVerfasst: Di 21.10.03 14:06 
Der Name Deines Rechners dürfte sich kaum ändern, egal ob Du im Netzwerk bist oder nicht.

barfuesser
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Di 21.10.03 14:08 
nein das meine ich nicht
ich meine wie ich die Computernamen die im netzwerk sind rausfinde ???
Horst
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 120



BeitragVerfasst: Di 21.10.03 19:29 
Hallo

schau mal auf folgende Webseite:

www.tif-masters.de/p...a/delphi/netz/4.html


hilf dir das weiter :?:

Gruß
Horst
:wave:
Jagg Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 635



BeitragVerfasst: Di 21.10.03 20:46 
hey cool danke aber wie bekomme ich die Computernamen raus die dadrin sind ???
Cyrus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Mi 22.10.03 09:37 
Im netzwerk spircht man nicht mehr von computernamen sondern von host namen mit diesen funktionen kannst du ip zu host und host zu ip auflösen:

ausblenden volle Höhe 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:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
function HostToIP; //Uses winsock
type
  TaPInAddr = array[0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
var
  list:Tstrings;
  phe: PHostEnt;
  pptr: PaPInAddr;
  I: Integer;
  GInitData: TWSAData;
  Phostname:array[0..255]of char;
begin
  Phostname:='';
  for i:=0 to length(Host)-1 do
  begin
    Phostname[i]:= Host[i+1];
  end;
  WSAStartup($101, GInitData);
  list := TstringList.Create;
  list.Clear;
  phe := gethostbyname(Phostname);
  if phe = nil then Exit;
  pPtr := PaPInAddr(phe^.h_addr_list);
  i    := 0;
  while pPtr^[i] <> nil do
  begin
    list.Add(inet_ntoa(pptr^[i]^));
    Inc(I);
  end;
  WSACleanup;
  result:='';
  for i:=0 to list.Count-1 do
  begin
    result:=result+list.Strings[i];
  end;
end;

function IPToHost;  //uses winsock
var 
  SockAddrIn: TSockAddrIn; 
  HostEnt: PHostEnt; 
  WSAData: TWSAData; 
begin 
  WSAStartup($101, WSAData); 
  SockAddrIn.sin_addr.s_addr := inet_addr(PChar(IPAddr)); 
  HostEnt := gethostbyaddr(@SockAddrIn.sin_addr.S_addr, 4, AF_INET); 
  if HostEnt <> nil then 
    Result := StrPas(Hostent^.h_name) 
  else 
    Result := ''; 
end;


Greetz Cyrus

_________________
Wer glaub er ist, hört auf zu werden!
Delphi Rulez!!!
achterburg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 50



BeitragVerfasst: Fr 24.10.03 18:03 
Hallo, sieht ja super aus,bis darauf, dass ich leider nichtviel versteh.Auf jedenfall wäre es nett, wenn einer mir sagen kann,welcheKlassen in dem Beispiel von Cyrus verwendet werden, weil er bei mir lauter undefinierte Bezeichner meldet. Außerdem hab ich die function von barfuesser getestet, klappt super, aber ich hätte gerne noch ne function, wo ich einfach die IP Adresse anzeigen lassen kann. Sollte ganz einfach sein, nur leider weiss ich nciht wie. Vielen, Dank,

achterburg
obbschtkuche
Gast
Erhaltene Danke: 1



BeitragVerfasst: Fr 24.10.03 18:14 
Cyrus hat folgendes geschrieben:
ausblenden Quelltext
1:
function HostToIP; //Uses winsock					



du musst winsock einbinden

[EDIT]

die Rümpfe sind falsch, die müssten so aussehen:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
function HostToIP(host: string): string//Uses winsock

//und

function IPToHost(ipaddr: string): string;  //uses winsock

[/delphi]
Sorryman
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 52



BeitragVerfasst: Do 30.10.03 10:16 
Hey sowas kann ich auch gebrauchen!

Aber mal eine Frage:
Wie bekomme ich denn eine Liste der aktiven Rechner im Netz raus? Hat da jemand ein einfaches Beispiel für?