Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   С/С++, C#, Delphi, .NET, Asm (https://forum.antichat.xyz/forumdisplay.php?f=24)
-   -   свой IP [Delphi] (https://forum.antichat.xyz/showthread.php?t=161791)

marcos 07.12.2009 18:57

свой IP [Delphi]
 
Всем привет! Подскажите как средствами Делфи узнать свой IP

OPF_Nik 07.12.2009 19:26

а что гугол сломалься??

Код:

uses
  Winsock;

{...}

function getIPs: Tstrings;
type
  TaPInAddr = array[0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
var
  phe: PHostEnt;
  pptr: PaPInAddr;
  Buffer: array[0..63] of Char;
  I: Integer;
  GInitData: TWSAData;
begin
  WSAStartup($101, GInitData);
  Result := TstringList.Create;
  Result.Clear;
  GetHostName(Buffer, SizeOf(Buffer));
  phe := GetHostByName(buffer);
  if phe = nil then Exit;
  pPtr := PaPInAddr(phe^.h_addr_list);
  I    := 0;
  while pPtr^[I] <> nil do
  begin
    Result.Add(inet_ntoa(pptr^[I]^));
    Inc(I);
  end;
  WSACleanup;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines := GetIps;
end;


DeaD_MoroZ 07.12.2009 19:34

Код:

uses
 ..., WinSock;


Function showIP : string;
type
  TaPInAddr = array [0..10] of PInAddr;
  PaPInAddr = ^TaPInAddr;
var
  phe  : PHostEnt;
  pptr : PaPInAddr;
  Buffer : array [0..63] of char;
  I    : Integer;
  GInitData      : TWSADATA;

Begin
  WSAStartup($101, GInitData);
  Result := '';
  GetHostName(Buffer, SizeOf(Buffer));
  phe :=GetHostByName(buffer);
  if phe = nil then Exit;
  pptr := PaPInAddr(Phe^.h_addr_list);
  I := 0;
  while pptr^[I] <> nil do begin
    Result := Result + StrPas(inet_ntoa(pptr^[I]^)) + '<-->' ;
    Inc(I);
  end;
  WSACleanup;
End;


DeaD_MoroZ 07.12.2009 19:36

Цитата:

Сообщение от OPF_Nik
DeaD_MoroZ а смысл 2 выкладывать?

пока писал ты уже выложил(= пару минут не успел...\=

OPF_Nik 07.12.2009 19:38

DeaD_MoroZ

бывает))) а все по тому, что кому то лень самому искать...


Время: 12:40