Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Delphi - Conoscere l'ip della propria macchina?
Forum - Delphi - Conoscere l'ip della propria macchina?

Avatar
thepunisher187 (Normal User)
Newbie


Messaggi: 7
Iscritto: 27/10/2008

Segnala al moderatore
Postato alle 17:29
Martedė, 24/03/2009
Scusate, vorrei sapere come fare, tramite un comando delphi, a conoscere l'indirizzo ip del mio computer per poi visualizzarlo a video...?
p.s. non intendo l'indirizzo che sia quando vai in internet, che puoi conoscere anche da siti tipo questo: http://www.unina2.it/assistenza/asp/indirizzo_IP.asp
ma intendo quello della rete lan a cui tu sei connesso e che ti viene assegnato (quindi l'indirizzo privato della macchina)...come fare?

PM Quote
Avatar
Darietto (Normal User)
Rookie


Messaggi: 32
Iscritto: 07/09/2008

Segnala al moderatore
Postato alle 19:42
Martedė, 24/03/2009
prova questa funzione

Codice sorgente - presumibilmente Delphi

  1. function GetIPFromHost
  2. (var HostName, IPaddr, WSAErr: string): Boolean;
  3. type
  4.   Name = array[0..100] of Char;
  5.   PName = ^Name;
  6. var
  7.   HEnt: pHostEnt;
  8.   HName: PName;
  9.   WSAData: TWSAData;
  10.   i: Integer;
  11. begin
  12.   Result := False;    
  13.   if WSAStartup($0101, WSAData) <> 0 then begin
  14.     WSAErr := 'Winsock is not responding."';
  15.     Exit;
  16.   end;
  17.   IPaddr := '';
  18.   New(HName);
  19.   if GetHostName(HName^, SizeOf(Name)) = 0 then
  20.   begin
  21.     HostName := StrPas(HName^);
  22.     HEnt := GetHostByName(HName^);
  23.     for i := 0 to HEnt^.h_length - 1 do
  24.      IPaddr :=
  25.       Concat(IPaddr,
  26.       IntToStr(Ord(HEnt^.h_addr_list^[i])) + '.');
  27.     SetLength(IPaddr, Length(IPaddr) - 1);
  28.     Result := True;
  29.   end
  30.   else begin
  31.    case WSAGetLastError of
  32.     WSANOTINITIALISED:WSAErr:='WSANotInitialised';
  33.     WSAENETDOWN      :WSAErr:='WSAENetDown';
  34.     WSAEINPROGRESS   :WSAErr:='WSAEInProgress';
  35.    end;
  36.   end;
  37.   Dispose(HName);
  38.   WSACleanup;
  39. end;


PM Quote