|
NAS的最终应用是代替本地硬盘,前提条件是有千兆有线网络,这个条件对于这个版块的常客来说并不苛刻。
在千兆有线网络应用中,DIY的台式机NAS性能相对较强,唯一常被诟病的是功耗问题。
对于纯NAS(不用做下载)的应用,NAS 24小时开机能随时使用NAS资源,用的比较爽。
NAS 24小时开机对于我而言,太费电,同时硬盘通电时间太长会影响今后的出售,我的解决方案是睡眠+网络唤醒。
这样能做到和NAS 24小时开机相同的效果,而且NAS从睡眠中唤醒最多5-10秒就可以了。
1、编写个网络唤醒软件
2、将这个软件在win7的计划任务中设置为登陆启动。
3、NAS中设置20分钟睡眠。
这样家里任何一台电脑启动都会启动NAS,应用中会让NAS变成本地硬盘一样使用方便。
程序自己参考了网上资源自己做了一个(VB)
下面是源程序:
'下面是源程序
Option Explicit
' 结构体变量声明
Private Type sockaddr
sin_family As Integer
sin_port As Integer
sin_addr As Long
sin_zero As String * 8
End Type
Private Type WSADataType
wVersion As Integer
wHighVersion As Integer
szDescription As String * 257
szSystemStatus As String * 129
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As Long
End Type
' TCP选项
Private Const AF_INET = 2 'TCP、UDP协议
' 连接类型
Private Const SOCK_DGRAM = 2 ' 数据报式socket
' 地址常量
Private Const INADDR_ANY = &H0
Private Const SOL_SOCKET = &HFFFF&
Private Const INVALID_SOCKET = -1
Private Const SOCKET_ERROR = -1
' 协议类型
Private Const IPPROTO_UDP = 17 ' 用户数据报协议
' 选项标志
Private Const SO_BROADCAST = &H20 ' 允许发送广播信息
' 其他
Private Const BUF_LEN = 102 ' 缓冲区大小
' API函数声明
Private Declare Function socket Lib "ws2_32.DLL" (ByVal af As Long, ByVal s_type As Long, ByVal protocol As Long) As Long '创建一个通讯端点并返回一个套接口
Private Declare Function WSAStartup Lib "ws2_32.DLL" (ByVal wVR As Long, lpWSAD As WSADataType) As Long
Private Declare Function WSACleanup Lib "ws2_32.DLL" () As Long
Private Declare Function closesocket Lib "ws2_32.DLL" (ByVal s As Long) As Long
Private Declare Function setsockopt Lib "ws2_32.DLL" (ByVal s As Long, ByVal level As Long, ByVal optname As Long, optval As Long, ByVal optlen As Long) As Long
Private Declare Function sendto Lib "ws2_32.DLL" (ByVal s As Long, Buf As Any, ByVal buflen As Long, ByVal flags As Long, to_addr As Any, ByVal tolen As Long) As Long
Private Function WakeRemoteComputer(MacAddress() As Byte) As Boolean
Dim msg_sock As Long
Dim remote_addr As sockaddr
Dim dwYes As Long
Dim SendData(0 To BUF_LEN - 1) As Byte, i As Integer
Dim wVersionRequested As Long ' 版本
Dim WSAData As WSADataType
WakeRemoteComputer = False
wVersionRequested = &H202
If WSAStartup(wVersionRequested, WSAData) = 0 Then
'获得winsock句柄
msg_sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
If msg_sock <> INVALID_SOCKET Then
' 允许进行广播
dwYes = 1
If setsockopt(msg_sock, SOL_SOCKET, SO_BROADCAST, dwYes, Len(dwYes)) <> SOCKET_ERROR Then
' 准备发送数据
For i = 0 To BUF_LEN - 1
SendData(i) = IIf(i < 6, &HFF, MacAddress(i Mod 6))
Next i
' 准备发送地址
remote_addr.sin_family = AF_INET
remote_addr.sin_port = 0
remote_addr.sin_addr = &HFFFFFFFF ' 广播地址255.255.255.255
' 发送UDP数据到远程计算机
If sendto(msg_sock, SendData(0), BUF_LEN, 0, remote_addr, Len(remote_addr)) <> SOCKET_ERROR Then
WakeRemoteComputer = True
End If
End If
closesocket msg_sock
End If
End If
WSACleanup
End Function
Sub main()
Dim MacAddress(0 To 5) As Byte, i As Integer
'MacAddress 中放置NAS的MAC的6位地址
MacAddress(0) = Val("&H" & "F4")
MacAddress(1) = Val("&H" & "6D")
MacAddress(2) = Val("&H" & "04")
MacAddress(3) = Val("&H" & "D9")
MacAddress(4) = Val("&H" & "F9")
MacAddress(5) = Val("&H" & "FE")
If WakeRemoteComputer(MacAddress()) Then
' MsgBox "唤醒包发送完成。 "
Else
MsgBox "不能发送唤醒包。 "
End If
End Sub
|
|