• Yeni Üyelik
  •     
  • K.Adı yada E-Posta :
  •      
  •      
End of Article
11 TEMMUZ

DELPHI - 7 - Delphi ile IP Bulma

Ekleyen: seasparrow 11 Temmuz 2005 Okunma: 1556
Yazdır

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Winsock, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

function DetectHostIP(var IP: string): Boolean;
var
wsdata : TWSAData;
hostName : array [0..255] of char;
hostEnt : PHostEnt;
addr : PChar;
begin
WSAStartup ($0101, wsdata);
try
gethostname (hostName, sizeof (hostName));
hostEnt := gethostbyname (hostName);
if Assigned (hostEnt) then
if Assigned (hostEnt^.h_addr_list) then begin
addr := hostEnt^.h_addr_list^;
if Assigned (addr) then begin
IP := Format ('%d.%d.%d.%d', [byte (addr [0]),
byte (addr [1]), byte (addr [2]), byte (addr [3])]);
Result := True;
end
else
Result := False;
end
else
Result := False
else begin
Result := False;
end;
finally
WSACleanup;
end
end;

procedure TForm1.Button1Click(Sender: TObject);

var IPAdres: string;
begin
if DetectHostIP(IPAdres) then
Label1.Caption := IpAdres
else
Label1.Caption := 'Ip Adresi alinamadi';

end;

end.