主题:刚做出来的VB远程唤醒电脑,太简单了,要代码的请进
'Text1为欲唤醒的电脑的物理地址(如:010203ABCDEF),MAC地址之间不能有任何其它字符(如:":","-"等),
'如果是在同一个局域网中,Text2填你的局域的广播地址,Text3默认为0得了。
'广域网远程开机还没来得及试,在Text2里填欲开机的电脑所在网络的公网IP,Text3填路由器里映射的端口,理论上是可以实现的。
Dim MagicPacket(0 To 101) As Byte
Dim myMAC(0 To 5) As Byte
Private Function HEX_to_DEC(ByVal Hex As String) As Long
Dim i As Long
Dim B As Long
Hex = UCase(Hex)
For i = 1 To Len(Hex)
Select Case Mid(Hex, Len(Hex) - i + 1, 1)
Case "0": B = B + 16 ^ (i - 1) * 0
Case "1": B = B + 16 ^ (i - 1) * 1
Case "2": B = B + 16 ^ (i - 1) * 2
Case "3": B = B + 16 ^ (i - 1) * 3
Case "4": B = B + 16 ^ (i - 1) * 4
Case "5": B = B + 16 ^ (i - 1) * 5
Case "6": B = B + 16 ^ (i - 1) * 6
Case "7": B = B + 16 ^ (i - 1) * 7
Case "8": B = B + 16 ^ (i - 1) * 8
Case "9": B = B + 16 ^ (i - 1) * 9
Case "A": B = B + 16 ^ (i - 1) * 10
Case "B": B = B + 16 ^ (i - 1) * 11
Case "C": B = B + 16 ^ (i - 1) * 12
Case "D": B = B + 16 ^ (i - 1) * 13
Case "E": B = B + 16 ^ (i - 1) * 14
Case "F": B = B + 16 ^ (i - 1) * 15
End Select
Next i
HEX_to_DEC = B
End Function
Private Sub StrToMAC(ByVal myStr As String)
Dim i As Integer
Dim tempStr As String
For i = 0 To 5
tempStr = Mid(myStr, i * 2 + 1, 2)
myMAC(i) = HEX_to_DEC(tempStr)
Next i
End Sub
Private Sub Command1_Click() '发送远程开机命令
Dim i As Integer
Call StrToMAC(Text1.Text)
Winsock1.RemoteHost = Text2.Text
Winsock1.RemotePort = Text3.Text
'以下两个For是设置魔术包
For i = 0 To 5
MagicPacket(i) = 255
Next i
For i = 6 To 101
MagicPacket(i) = myMAC((i Mod 6))
Next i
Winsock1.SendData MagicPacket
End Sub
Private Sub Form_Load()
Winsock1.Protocol = sckUDPProtocol '使用UDP协议
Text1.Text = "010203ABCDEF" 'MAC地址填写的格式要求这样填
Text2.Text = "192.168.1.255" '广播地址
Text3.Text = "0"
End Sub
'如果是在同一个局域网中,Text2填你的局域的广播地址,Text3默认为0得了。
'广域网远程开机还没来得及试,在Text2里填欲开机的电脑所在网络的公网IP,Text3填路由器里映射的端口,理论上是可以实现的。
Dim MagicPacket(0 To 101) As Byte
Dim myMAC(0 To 5) As Byte
Private Function HEX_to_DEC(ByVal Hex As String) As Long
Dim i As Long
Dim B As Long
Hex = UCase(Hex)
For i = 1 To Len(Hex)
Select Case Mid(Hex, Len(Hex) - i + 1, 1)
Case "0": B = B + 16 ^ (i - 1) * 0
Case "1": B = B + 16 ^ (i - 1) * 1
Case "2": B = B + 16 ^ (i - 1) * 2
Case "3": B = B + 16 ^ (i - 1) * 3
Case "4": B = B + 16 ^ (i - 1) * 4
Case "5": B = B + 16 ^ (i - 1) * 5
Case "6": B = B + 16 ^ (i - 1) * 6
Case "7": B = B + 16 ^ (i - 1) * 7
Case "8": B = B + 16 ^ (i - 1) * 8
Case "9": B = B + 16 ^ (i - 1) * 9
Case "A": B = B + 16 ^ (i - 1) * 10
Case "B": B = B + 16 ^ (i - 1) * 11
Case "C": B = B + 16 ^ (i - 1) * 12
Case "D": B = B + 16 ^ (i - 1) * 13
Case "E": B = B + 16 ^ (i - 1) * 14
Case "F": B = B + 16 ^ (i - 1) * 15
End Select
Next i
HEX_to_DEC = B
End Function
Private Sub StrToMAC(ByVal myStr As String)
Dim i As Integer
Dim tempStr As String
For i = 0 To 5
tempStr = Mid(myStr, i * 2 + 1, 2)
myMAC(i) = HEX_to_DEC(tempStr)
Next i
End Sub
Private Sub Command1_Click() '发送远程开机命令
Dim i As Integer
Call StrToMAC(Text1.Text)
Winsock1.RemoteHost = Text2.Text
Winsock1.RemotePort = Text3.Text
'以下两个For是设置魔术包
For i = 0 To 5
MagicPacket(i) = 255
Next i
For i = 6 To 101
MagicPacket(i) = myMAC((i Mod 6))
Next i
Winsock1.SendData MagicPacket
End Sub
Private Sub Form_Load()
Winsock1.Protocol = sckUDPProtocol '使用UDP协议
Text1.Text = "010203ABCDEF" 'MAC地址填写的格式要求这样填
Text2.Text = "192.168.1.255" '广播地址
Text3.Text = "0"
End Sub