question: public static boolean sendWolMagicPacket ( String macAddress , String hostAddress , int port ) { if ( macAddress == null ) { return false ; } byte [ ] macAddressBytes = new byte [ 6 ] ; String [ ] hex = macAddress . split ( "(\\:|\\-)" ) ; if ( hex . length != 6 ) { LogUtils . LOGD ( TAG , "Send magic packet: got an invalid MAC address: " + macAddress ) ; return false ; } try { for ( int i = 0 ; i < 6 ; i ++ ) { macAddressBytes [ i ] = ( byte ) Integer . parseInt ( hex [ i ] , 16 ) ; } } catch ( NumberFormatException e ) { LogUtils . LOGD ( TAG , "Send magic packet: got an invalid MAC address: " + macAddress ) ; return false ; } byte [ ] bytes = new byte [ 6 + 16 * macAddressBytes . length ] ; for ( int i = 0 ; i < 6 ; i ++ ) { bytes [ i ] = ( byte ) 0xff ; } for ( int i = 6 ; i < bytes . length ; i += macAddressBytes . length ) { System . arraycopy ( macAddressBytes , 0 , bytes , i , macAddressBytes . length ) ; } try { InetAddress address = InetAddress . getByName ( hostAddress ) ; DatagramPacket packet = new DatagramPacket ( bytes , bytes . length , address , port ) ; DatagramSocket socket = new DatagramSocket ( ) ; LogUtils . LOGD ( TAG , "Sending WoL to " + address . getHostAddress ( ) + ":" + port ) ; socket . send ( packet ) ; Enumeration < NetworkInterface > interfaces = NetworkInterface . getNetworkInterfaces ( ) ; while ( interfaces . hasMoreElements ( ) ) { NetworkInterface networkInterface = interfaces . nextElement ( ) ; if ( networkInterface . isLoopback ( ) ) continue ; for ( InterfaceAddress interfaceAddress : networkInterface . getInterfaceAddresses ( ) ) { InetAddress broadcast = interfaceAddress . getBroadcast ( ) ; if ( broadcast != null ) { LogUtils . LOGD ( TAG , "Sending WoL broadcast to " + broadcast . getHostAddress ( ) + ":" + port ) ; packet = new DatagramPacket ( bytes , bytes . length , broadcast , port ) ; socket . send ( packet ) ; } } } socket . close ( ) ; } catch ( IOException e ) { LogUtils . LOGD ( TAG , "Exception while sending magic packet." , e ) ; return false ; } return true ; }
target:  Sends a Wake On Lan magic packet to a host Note: This is a synchronous call, so it should only be called on a background thread