网络唤醒应该怎么做?(100分)

  • 主题发起人 主题发起人 xhhua
  • 开始时间 开始时间
X

xhhua

Unregistered / Unconfirmed
GUEST, unregistred user!
在局域网中,网卡和主板都支持 wake on lan ,
软件应该怎么样做.
先谢了.
 
//------------------------------------------------------------------------------
// 司马华鹏
function GetStrFormMacHex(StrHex:string): String;
function HexToInt(Hex: String): Integer;
var
I, Res: Integer;
ch: Char;
begin
Res := 0;
for I := 0 to Length(Hex) - 1 do
begin
ch := Hex[I + 1];
if (ch >= '0') and (ch <= '9') then
Res := Res * 16 + Ord(ch) - Ord('0')
else if (ch >= 'A') and (ch <= 'F') then
Res := Res * 16 + Ord(ch) - Ord('A') + 10
else if (ch >= 'a') and (ch <= 'f') then
Res := Res * 16 + Ord(ch) - Ord('a') + 10
else raise Exception.Create('Error: not a Hex String');
end;
Result := Res;
end;

var
Temp: String;
I: Integer;
begin
for I := 0 to Length(StrHex) div 2 - 1 do
begin
Temp := Copy(StrHex, I * 2 + 1, 2);
Result := Result + String(Char(HexToInt(Temp)));
end;
end;

//------------------------------------------------------------------------------
// 司马华鹏
procedure TfrmServer.UDPSend(SendCode: String);
var
Strm:TMemoryStream;
begin
Strm:=TMemoryStream.Create;
try
NMUDP1.ReportLevel:=1;
NMUDP1.RemoteHost:=GetBoardAddr(GetLocalIP);
NMUDP1.RemotePort:=10240;
Strm.Write(SendCode[1],length(SendCode));
NMUDP1.SendStream(Strm);
finally
Strm.Free;
end;
end;

//------------------------------------------------------------------------------
procedure TfrmServer.btnWakeClick(Sender: TObject);
var
SendCode:string;
TempStr:string;
strMac:string;
strSet:string;
i,j:integer;
begin
SendCode:=StringofChar(#255,6); // 前导为6个FF
TempStr:='';
strSet:=GetStrFormMacHex(strMac); // 将MAC地址转化为字符

for i:=0 to 15 do
begin
TempStr:=TempStr + strSet; // 将转化的MAC地址重复16次
end;

SendCode:=SendCode+TempStr; // 连接字符
UDPSend(SendCode); // 发送字符
end;
 
谢谢回答,
再请问, 通过网络关机又如何实现.
 
如果被唤醒端可以运行程序,就些个服务什么的,如同木马一样就可以了。
 
被唤醒端不可以运行程序,还是通过网卡,如何用软件实现关机.谢谢.
 
//------------------------------------------------------------------------------
// NT下提升权限
// 司马华鹏
procedure AdjustTokenPrivilegesNT();
var
hdlProcessHandle:cardinal;
hdlTokenHandle:cardinal;
tmpLuid:int64;
tkp:TOKEN_PRIVILEGES;
tkpNewButIgnored:TOKEN_PRIVILEGES;
lBufferNeeded:cardinal;
begin
hdlProcessHandle:=GetCurrentProcess();
OpenProcessToken(hdlProcessHandle,
TOKEN_ADJUST_PRIVILEGES + TOKEN_QUERY,
hdlTokenHandle);

LookupPrivilegeValue(pChar(''),pChar('SeShutdownPrivilege'),tmpLuid);
tkp.PrivilegeCount := 1;
tkp.Privileges[0].Luid := tmpLuid;
tkp.Privileges[0].Attributes := SE_PRIVILEGE_ENABLED;

AdjustTokenPrivileges(hdlTokenHandle, False, tkp,
sizeof(tkpNewButIgnored), tkpNewButIgnored,
lBufferNeeded);
end;

// 强制退出系统
AdjustTokenPrivilegesNT;
ExitWindowsEx(EWX_FORCE or EWX_POWEROFF, 0);
 
接受答案了.
 
后退
顶部