怎樣判斷局域網中的某台電腦是開機還是關機?(50分)

  • 主题发起人 主题发起人 jsxs
  • 开始时间 开始时间
J

jsxs

Unregistered / Unconfirmed
GUEST, unregistred user!
已知局域網中的某台電腦的名字和IP(比如:名字為PC1,IP為192.168.0.25), 怎樣判斷局域網中的這台電腦是開機還是關機?用delphi怎麼寫?越簡單越好。我只是判斷這台電腦是開機還是關機!希望如下:
if ping(192.168.0.25) is 通 then
showmessage('已經開機');
if ping(192.168.0.25) is 不通 then
showmessage('已經關機');
怎麼寫呢?
 
请参考以下帮助:
The Windows Sockets gethostbyaddr function gets host information corresponding to an address.

struct hostent FAR * gethostbyaddr (

const char FAR * addr,
int len,
int type
);


Parameters

addr

[in] A pointer to an address in network byte order.

len

[in] The length of the address.

type

[in] The type of the address.



Remarks

gethostbyaddr returns a pointer to the following hostent structure which contains the name(s) and address which correspond to the given address. All strings are null terminated.

Return Values

If no error occurs, gethostbyaddr returns a pointer to the hostent structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.

Error Codes

WSANOTINITIALISED A successful WSAStartup must occur before using this function.
WSAENETDOWN The network subsystem has failed.
WSAHOST_NOT_FOUND Authoritative Answer Host not found.
WSATRY_AGAIN Non-Authoritative Host not found, or server failed.
WSANO_RECOVERY Nonrecoverable error occurred.
WSANO_DATA Valid name, no data record of requested type.
WSAEINPROGRESS A blocking Windows Sockets 1.1 call is in progress, or the service provider is still processing a callback function.
WSAEAFNOSUPPORT The type specified is not supported by the Windows Sockets implementation.
WSAEFAULT The addr argument is not a valid part of the user address space, or the len argument is too small.
WSAEINTR The (blocking) call was canceled through WSACancelBlockingCall.


See Also

gethostbyname, hostent, WSAAsyncGetHostByAddr
 
TO:chnplzh
我想要一個很簡單的做法,我只是判斷這台電腦是開機還是關機!希望如下:
if ping(192.168.0.25) is 通 then
showmessage('已經開機');
if ping(192.168.0.25) is 不通 then
showmessage('已經關機');
 
function Ping(HostName: string;
TimeOut: integer): string;
var
ICMP: TIdIcmpClient;
begin
Result := '';
ICMP := TIdIcmpClient.Create(nil);
try
ICMP.ReceiveTimeout := Timeout;
ICMP.Host := HostName;
ICMP.Ping;
Result := ICMP.ReplyStatus.FromIpAddress;
ICMP.Free;
except
ICMP.Free;
end;
end;

if Ping('192.168.1.10', 3000)='' then
已关机
 
搂主:
Return Values
If no error occurs, gethostbyaddr returns a pointer to the hostent structure described above. Otherwise, it returns a NULL pointer and a specific error number can be retrieved by calling WSAGetLastError.
已经很简单了。
 
TO:特尔斐
不能正確的進行判斷! 你測試過嗎?
TO:chnplzh
老大,具體怎麼寫?
 
TIdIcmpClient;
是否在D7裡沒有呀?
 
TO:特尔斐
不能正確的進行判斷! 你測試過嗎?
TO:chnplzh
老大,具體怎麼寫?
 
uses winsock;

function iptoname(ip:string):string;
var
WSAData:TWSAData;
p:PHostEnt;
InetAddr:dword;
begin
WSAStartup(2, WSAData);
InetAddr:= inet_addr(PChar(IP));
try
p:=GetHostByAddr(@InetAddr, Length(IP), PF_Inet);
result:=p^.h_name;
except
result:='';
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if iptoname('192.168.0.25') = '' then showmessage('shutdown');
end;

 
TO:peg_qs
可以啦,謝謝!
 
后退
顶部