![]() |
| ||
|
|
Новости |
Поиск |
FAQ |
Статьи |
Книги |
Новости VCL
| | Форумы ЧАТ |
Орешник |
|
| |||
| |||
« предыдущая ветвь | форум | следующая ветвь »
Определение компа в локальной сети
peek © (2004-07-24 14:11:00)Как определить, в сети ли комп под определенным IP?
Dolt (2004-07-24 14:34:00) [1]Я себе сделал так, возможно, это не самый оптимальный вариант:
-----------------
(*
Узнать, подключен ли к сети компьютер.
Параметр - IP-адрес компа
Код возврата:
0 - комп найден
1 - комп не найден
5 - нет параметра
2004.04.22 Create ddiner
*)
program GetCompStatus;
uses
SysUtils,
Windows;
Var
screenexe:String='nbtstat -A ';
s:String;
procedure Dos2Win(CmdLine : string; var Line : string);
const BUFSIZE = 2000;
var SecAttr : TSecurityAttributes;
hReadPipe,
hWritePipe : THandle;
StartupInfo : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
WaitReason,
BytesRead : DWord;
begin
with SecAttr do
begin
nlength := SizeOf(TSecurityAttributes);
binherithandle := true;
lpsecuritydescriptor := nil;
end;
if Createpipe (hReadPipe, hWritePipe, @SecAttr, 0) then
begin
Buffer := AllocMem(BUFSIZE + 1);
FillChar(StartupInfo, Sizeof(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.hStdOutput := hWritePipe;
StartupInfo.hStdInput := hReadPipe;
StartupInfo.dwFlags := STARTF_USESTDHANDLES +
STARTF_USESHOWWINDOW;
StartupInfo.wShowWindow := SW_HIDE;
if CreateProcess(nil, PChar(CmdLine), @SecAttr, @SecAttr, true,
NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then
begin
repeat
WaitReason := WaitForSingleObject( ProcessInfo.hProcess,100);
sleep(100);
until (WaitReason <> WAIT_TIMEOUT);
repeat
BytesRead := 0;
ReadFile(hReadPipe, Buffer[0], BUFSIZE, BytesRead, nil);
Buffer[BytesRead]:= #0;
OemToAnsi(Buffer,Buffer);
Line := Line + string(Buffer);
until (BytesRead < BUFSIZE);
end;
FreeMem(Buffer);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(hReadPipe);
CloseHandle(hWritePipe);
end;
end;
begin
ExitCode:=5;
If paramCount>0 Then begin
s:='';
screenexe:=screenexe+paramstr(1);
Dos2Win(screenexe,s);
If (pos('(MAC)',s)>0)or(pos('(mac)',s)>0) then BEGIN
ExitCode:=0
END
else begin
ExitCode:=1
end;
end;
end.
Anatoly Podgoretsky (2004-07-24 14:25:00) [2]Определить на что он может откликаться, если ни на что, то никак
Polevi (2004-07-24 14:22:00) [3]SendArp