1. 程式人生 > >遠程開機 .java

遠程開機 .java

遠程開機

import java.io.IOException;

import java.net.*;

import java.util.*;


public class 遠程開機 {


public static void main(String[] args) {


DatagramSocket ds = null; //建立套間字udpsocket服務


try {

ds = new DatagramSocket(9999); //實例化套間字,指定自己的port

} catch (SocketException e) {

System.out.println("Cannot open port!");

System.exit(1);

}

byte a = Integer.valueOf(0xb8).byteValue();

byte b = Integer.valueOf(0x97).byteValue();

byte c = Integer.valueOf(0x5a).byteValue();

byte d = Integer.valueOf(0x68).byteValue();

byte e = Integer.valueOf(0x64).byteValue();

byte f = Integer.valueOf(0x6f).byteValue();

byte g = Integer.valueOf(0xff).byteValue();

byte[] buf= {g,g,g,g,g,g,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f,a,b,c,d,e,f};

//(0xb8)(0x97)(0x5a)(0x68)(0x64)(0x6f)

InetAddress destination = null ;

try {

destination = InetAddress.getByName("255.255.255.255"); //需要發送的地址

} catch (UnknownHostException o) {

System.out.println("Cannot open findhost!");

System.exit(1);

}

DatagramPacket dp =

new DatagramPacket(buf, buf.length, destination , 9);

//打包到DatagramPacket類型中(DatagramSocket的send()方法接受此類,註意10000是接受地址的端口,不同於自己的端口!)


try {

ds.send(dp); //發送數據

} catch (IOException o) {

System.out.println(o.getMessage());

}

ds.close();

}

}


遠程開機 .java