有三种方法(只是我知道的) 1.ping winexec(pchar('command.com /c ping'+host),sw_show); //host为你要的主机ip或主机名 2,net view winexe(pchar('command.com /c net view'),sw_show); 3gethostbyname function findcomputer(computername:string):boolean; var wsadata:Twsadata; hostent:Phostent; begin Result:=true; wsastartup(2,wsadata); hostent:=gethostbyname(pchar(computername)); if hostent=nil then result:=false; wsacleanup; button1 onclick begin if findcomputer(edit1.text)=true then showmessage(edit1.text+'在局域网上') else showmessage(edit1.text+'不在局域网上');对了不要忘了加 uses winsock; end; end;
1.ping
winexec(pchar('command.com /c ping'+host),sw_show);
//host为你要的主机ip或主机名
2,net view
winexe(pchar('command.com /c net view'),sw_show);
3gethostbyname
function findcomputer(computername:string):boolean;
var
wsadata:Twsadata;
hostent:Phostent;
begin
Result:=true;
wsastartup(2,wsadata);
hostent:=gethostbyname(pchar(computername));
if hostent=nil then result:=false;
wsacleanup;
button1 onclick
begin
if findcomputer(edit1.text)=true then
showmessage(edit1.text+'在局域网上')
else
showmessage(edit1.text+'不在局域网上');对了不要忘了加
uses winsock;
end;
end;