Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

Network dolu ip leri bulma bulunan ip lerin ismini bulma

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient, Buttons,winsock; type TForm1 = class(TForm) SpeedButton1: TSpeedButton; Pinger1: TIdIcmpClient; Status: TMemo; Hostrange: TEdit; Memo1: TMemo; Button1: TButton; procedure SpeedButton1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Pinger1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function LocalIP: 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 := inet_ntoa(pptr^[I]^); Inc(I); end; WSACleanup; end; function IPAddrToName(IPAddr: string): string; 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; procedure TForm1.SpeedButton1Click(Sender: TObject); var I: Integer; V: String; begin Status.Clear; V := Hostrange.text; for I := 1 to 255 do begin with Pinger1 do begin ReceiveTimeout := 200; Host := V + IntToStr(I); Ping; case ReplyStatus.ReplyStatusType of rsEcho: Status.Lines.Add(Host); rsError, rsTimeOut, rsErrorUnreachable, rsErrorTTLExceeded: end; end; end; end; procedure TForm1.FormCreate(Sender: TObject); begin Hostrange.Text := '192.168.0.'; end; procedure TForm1.Pinger1Reply(ASender: TComponent; const AReplyStatus: TReplyStatus); begin //AReplyStatus end; procedure TForm1.Button1Click(Sender: TObject); var i:integer; begin for i:= 0 to status.Lines.Count-1 do begin Memo1.Lines.Add(status.Lines[i]+ IPAddrToName(status.Lines[i])) ; end; end; end.