vb.net - Remote PC not turning on using Wake on LAN -
hi using code.. not working.. have checked packets receiving on remote computer keeping remote pc turn on... when remote pc turned off not getting turn on
public class form1 private sub form1_load(byval sender object, byval e system.eventargs) handles me.load sendmagicpacket("ip", "mac addr", "sub net") 'remote pc details end sub public sub sendmagicpacket(byval ipaddress string, byval strmacaddress string, byval strlansubnet string) dim macaddress string = string.empty dim wanipaddr string = string.empty dim lansubnet string = string.empty dim strbroadcast string = string.empty dim port integer = 9 dim altport integer = 7 dim udpclient new system.net.sockets.udpclient dim buf(101) char dim sendbytes [byte]() = system.text.encoding.ascii.getbytes(buf) macaddress = strmacaddress wanipaddr = ipaddress lansubnet = strlansubnet x integer = 0 5 sendbytes(x) = cbyte("&hff") next macaddress = macaddress.replace("-", "").replace(":", "") dim integer = 6 x integer = 1 16 sendbytes(i) = cbyte("&h" + macaddress.substring(0, 2)) sendbytes(i + 1) = cbyte("&h" + macaddress.substring(2, 2)) sendbytes(i + 2) = cbyte("&h" + macaddress.substring(4, 2)) sendbytes(i + 3) = cbyte("&h" + macaddress.substring(6, 2)) sendbytes(i + 4) = cbyte("&h" + macaddress.substring(8, 2)) sendbytes(i + 5) = cbyte("&h" + macaddress.substring(10, 2)) += 6 next dim myaddress string try myaddress = net.ipaddress.parse(wanipaddr).tostring catch ex exception msgbox("packet send failed. see log") 'log("magic packet failed! ip address appears invalid! error: " & ex.message) exit sub end try if myaddress = string.empty messagebox.show("invalid ip address/host name given") return end if dim mysubnetarray() string mysubnetarray = lansubnet.split(".") strbroadcast = calculatebroadcastaddress(ipaddress, strlansubnet) myaddress = wanipaddr try 'log("magic packet sent data - ip:" & ipaddress & ", broadcast: " & strbroadcast & ", mac: " & strmacaddress & ", subnet: " & strlansubnet) 'send magic packet broadcast ip udpclient.send(sendbytes, sendbytes.length, strbroadcast, port) udpclient.send(sendbytes, sendbytes.length, strbroadcast, altport) 'send magic packet pc's ip udpclient.send(sendbytes, sendbytes.length, ipaddress, port) udpclient.send(sendbytes, sendbytes.length, ipaddress, altport) udpclient = nothing msgbox("magic packet sent! computer should power on if wake-on-lan enabled.") shell("ping -t " & ipaddress, appwinstyle.normalfocus) catch ex exception msgbox("error sending macgic packet. error: " & ex.message) end try end sub public function calculatebroadcastaddress(byval currentip string, byval ipnetmask string) string dim strcurrentip string() = currentip.tostring().split(".") dim stripnetmask string() = ipnetmask.tostring().split(".") dim arbroadcast arraylist = new arraylist() dim itotalsubnets integer = 2 ^ borrowedbits(stripnetmask(3)) dim ihosts integer = 2 ^ (8 - borrowedbits(stripnetmask(3))) dim isubnetnum integer dim iipoctet integer = strcurrentip(3) if iipoctet / ihosts < 1 isubnetnum = 0 else isubnetnum = (iipoctet / ihosts) - ((iipoctet / ihosts) mod 1) end if integer = 0 3 if <> 3 arbroadcast.add(strcurrentip(i)) else arbroadcast.add((ihosts * isubnetnum) + (ihosts - 1)) end if next return arbroadcast(0) & "." & arbroadcast(1) & "." & arbroadcast(2) & "." & arbroadcast(3) end function function borrowedbits(byval inum int32) int32 select case inum case 255 return 8 case 254 return 7 case 252 return 6 case 248 return 5 case 240 return 4 case 224 return 3 case 192 return 2 case 128 return 1 case 0 return 0 end select end function end class
Comments
Post a Comment