Android Question help wake on lan

Discussion in 'Android Questions' started by netklamath, Nov 3, 2013.

  1. netklamath

    netklamath Member Licensed User

    Is there any way I can do WOL?

    How do I tell the socket to the mac sending the packet?
     
  2. DKCERT

    DKCERT Member Licensed User

    You can make your own WOL code and have full control. This is a short description:

    A Wake-On-LAN packet is an normal UDP packet with a header and the MAC address of the target computer. The UDP packet is 16 times the byte representation of the MAC address, plus the extra 6 bytes for a header. This makes the total packet size 6 + 16*6 = 102 bytes.
    • The first 6 bytes are filled with 0xFF (-> 255,255,255,255,255,255).
    • The next 6 bytes are the MAC address of the (e.g. 00:1A:2B:3C:4D:5E -> 0,26,43,60,77,94).
    • Each following set of 6 bytes are also filled with the target computer MAC address until the packet is full.
    The UDP packet is normally sent to LAN broadcast address (e.g. 192.168.x.255). All computers on your LAN will recieve this, but only the one with a matching MAC address will respond and power on. The WOL UDP packet normally uses port 9. Note: As UDP packets are not guaranteed you may need to send it more than once.

    I hope it is useful.
     
    Last edited: Nov 3, 2013
  3. netklamath

    netklamath Member Licensed User

    Thanks for your help. I tried but did not work. Would you be so kind as to get the exact code to copy and paste?
     
  4. monki

    monki Active Member Licensed User

    A few months ago I wrote this class for WOL.
    you can use it as follows.
    Add new class module named as Wakeonlan
    Copie code in the class module.
    Mark Network and Byteconverter in the Libs Tab.

    Example:

    Dim wol As Wakeonlan
    wol.Initialize
    wol.Wake (You macadress target) 'Example wol.Wake ("58:53: EF: 6F: 26:29")

    Monki

    Code:
    'Class module
    Private Sub Class_Globals
        
    Private UDPSocket1 As UDPSocket
        
    Private bcon As ByteConverter
        
    Private Packet As UDPPacket
    End Sub

    'Initializes the object. You can add parameters to this method if needed.
    Public Sub Initialize
    UDPSocket1.Initialize(
    "",08000)
    End Sub


    Public Sub Wake(Mac As String)
        
    Dim barry() As Byte
        
    Dim data(102As Byte
        
    For t=0 To 5                                        '6x FF to Buffer
            data(t)=Bit.OR(data(t),255)
        
    Next
        
    Try
            barry=bcon.HexToBytes(
    Mac)                        'HEX to Byte
            For x =6 To 96 Step 6                            '16x Mac-Adresse to Buffer
                bcon.ArrayCopy (barry, 0, data,x,6)
            
    Next
            Packet.Initialize(data,
    "255.255.255.255",9)
            UDPSocket1.Send(Packet)                            
    'Magic Packet send
        Catch
            
    ToastMessageShow("Error "&LastException.Message,True)
        
    End Try
    End Sub
     
    walt61, haufe and moster67 like this.
  5. netklamath

    netklamath Member Licensed User


    hello again. Sorry. I did as you said and it does not work.

    I get this error: java.lang.Exception: hex string has odd number of characters

    Would you be so kind to send me an example?. I really appreciate it
     
  6. monki

    monki Active Member Licensed User

    Hello,
    my mistake
    The MAC address must be passed as a string without double points.

    ex. Example wol.Wake ("5853EF6F2629")
     
  7. netklamath

    netklamath Member Licensed User

    ok, I'll try. Thanks



    It works for me. Thank you so much for everything!
     
    Last edited: Nov 4, 2013
Loading...