Velhim eu fiz um codigo utilizando o winsock coloeuqie um timer e ele retrona pra mim primeiro se a rede estar atiava e depois se o ip que setei esta ativo ...
da uma olhada ai n codigo Espero que ajude... Wash Moratti unit Uprincipal; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, ComCtrls, IniFiles, StdCtrls, Winsock, IdBaseComponent, IdComponent, IdRawBase, IdRawClient, IdIcmpClient; type TfPrincipal = class(TForm) Timer1: TTimer; stbar: TStatusBar; btLerConfig: TButton; lbIp: TLabel; lbCaminho: TLabel; edIp: TEdit; Ip: TLabel; btGravarIp: TButton; Label1: TLabel; procedure Timer1Timer(Sender: TObject); procedure btLerConfigClick(Sender: TObject); procedure btGravarIpClick(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } config : TIniFile ; ipCfg : string; function buscaIp: string; public { Public declarations } end; var fPrincipal: TfPrincipal; implementation uses UPing; {$R *.dfm} function GetLocalIP: 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 := StrPas(inet_ntoa(pptr^[I]^)); result := StrPas(inet_ntoa(pptr^[I]^)); Inc(I); end; WSACleanup; end; procedure TfPrincipal.Timer1Timer(Sender: TObject); var IpLocal : string; begin IpLocal := GetLocalIp; // Comarando se é Servidor ou Estação if ( buscaIp = IpLocal ) or ( buscaIp = '127.0.0.1' ) then begin // Se for Servidor executa: fPrincipal.Color := clBtnFace; stbar.Panels[0].Text := 'Servidor'; stbar.Panels[1].Text := 'IP local é :' + IpLocal; end else begin // Se for estação executa: if Iplocal = '127.0.0.1' then begin // Se a Rede estiver Desativada Executa: Stbar.Panels[0].Text := 'Rede Desativada.'; stbar.Panels[1].Text := 'Servidor não encontrado !!!'; fPrincipal.Color := clInfoBk; end else begin // Se a Rede estiver Ativada Executa: Stbar.Panels[0].Text := 'Estação e seu Ip é: ' + GetLocalIP; fPrincipal.Color := clBtnFace; If Ping(buscaIp) then begin fPrincipal.Color := clBtnFace; stbar.Panels[1].Text := 'Servidor encontrado !!!'; end else begin fPrincipal.Color := clInfoBk; stbar.Panels[1].Text := 'Servidor não encontrado !!!'; end; end; end; end; procedure TfPrincipal.btLerConfigClick(Sender: TObject); begin config := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'config.ini'); try lbIp.Caption := config.ReadString('rede','ip',''); lbCaminho.Caption := config.ReadString('rede','caminho',ExtractFilePath(Application.ExeName)); finally config.Free; end; end; procedure TfPrincipal.btGravarIpClick(Sender: TObject); begin config := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'config.ini'); try config.WriteString('rede','ip',edIp.Text); finally Config.Free; end; btLerConfigClick(btLerConfig); end; procedure TfPrincipal.FormShow(Sender: TObject); begin if not FileExists(ExtractFilePath(Application.ExeName) + 'config.ini') then begin config := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'config.ini'); try config.WriteString('rede','ip',''); config.WriteString('rede','caminho',ExtractFilePath(Application.ExeName)); finally config.Free; end; end; end; function TfPrincipal.buscaIp: string; begin if FileExists(ExtractFilePath(Application.ExeName) + 'config.ini') then begin config := TIniFile.Create(ExtractFilePath(Application.ExeName) + 'config.ini'); try result := config.ReadString('rede','ip',''); finally config.Free; end; end; end; procedure TfPrincipal.FormCreate(Sender: TObject); begin buscaIp; end; end. [As partes desta mensagem que não continham texto foram removidas]