「java远程唤醒」远程唤醒命令

博主:adminadmin 2022-12-31 20:15:08 520

今天给各位分享java远程唤醒的知识,其中也会对远程唤醒命令进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

java多线程怎么唤醒特定线程

java使用单纯的wait/notify是无法唤醒指定线程的

一般的做法是修改一个特定标识,然后notifyAll,被唤醒的线程查看该标识是否指定自己处理,是就运行下去,不是就继续wait

还有一种做法是针对每一个线程做一个wait object,要唤醒哪一个就notify哪一个object就行了,但是能不能这样做去取决于你的业务需求

求助:高分求用java实现walk-on-lan的代码!!!

联系我,发给你一个吧~~我的邮箱 yanli3130@126.com

这是主要的代码

/*

* WakeFrame.java

*

* Created on 2007年9月6日 下午9:06

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

package wakelan;

/**

*

* @author hyj

*/

import java.awt.*;

import java.awt.event.*;

import java.text.*;

import javax.swing.*;

import javax.swing.text.*;

import java.io.*;

import java.net.*;

import java.util.*;

public class WakeFrame extends JFrame implements ActionListener,ItemListener {

/** Creates a new instance of WakeFrame */

public WakeFrame() {

super("局域网远程唤醒工具");

width=300;

height=160;

setSize(width,height);

Toolkit tk=this.getToolkit();

int scrWidth=tk.getScreenSize().width;

int scrHeight=tk.getScreenSize().height;

setLocation((scrWidth-width)/2,(scrHeight-height)/2);

setResizable(false);

datafile="maclist.txt";

MACArray=new Vector();

try{

BufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(datafile)));

String address;

while((address=reader.readLine())!=null){

MACArray.addElement(address.substring(address.indexOf("--")+2));

}

reader.close();

reader=null;

}catch(FileNotFoundException fnfe){

JOptionPane.showMessageDialog(this,"MAC地址数据文件不存在!","程序错误",JOptionPane.ERROR_MESSAGE);

}catch(IOException ioe){

JOptionPane.showMessageDialog(this,"MAC地址数据输入出现错误","程序错误",JOptionPane.ERROR_MESSAGE);

}

port=9;

initComponents();

}

private void initComponents(){

Container container=this.getContentPane();

container.setLayout(new GridLayout(4,2,20,10));

ListLabel=new JLabel("目标主机列表");

MACList=new JComboBox(MACArray);

MACList.addItemListener(this);

MACLabel=new JLabel("目标主机");

BroadcastLabel=new JLabel("广播地址");

MACAddr=new JTextField(17);

BroadcastAddr=new JTextField(15);

OKButton=new JButton("确定");

OKButton.addActionListener(this);

ExitButton=new JButton("退出");

ExitButton.addActionListener(this);

container.add(ListLabel);

container.add(MACList);

container.add(MACLabel);

container.add(MACAddr);

container.add(BroadcastLabel);

container.add(BroadcastAddr);

container.add(OKButton);

container.add(ExitButton);

}

public void actionPerformed(ActionEvent e){

if(e.getSource()==OKButton){

try{

String[] hex=MACAddr.getText().split(":");

byte[] MACbytes=new byte[6];

int i;

for(i=0;i6;i++){

MACbytes[i]=(byte)Integer.parseInt(hex[i], 16);

}

byte[] magicPacket=new byte[6+16*MACbytes.length];

for(i=0;i6;i++)

magicPacket[i]=(byte)0xff;

for(i=6;imagicPacket.length;i+=MACbytes.length){

System.arraycopy(MACbytes,0,magicPacket,i,MACbytes.length);

}

InetAddress address=InetAddress.getByName(BroadcastAddr.getText());

DatagramPacket packet=new DatagramPacket(magicPacket,magicPacket.length,address,port);

DatagramSocket socket=new DatagramSocket();

socket.send(packet);

socket.close();

JOptionPane.showMessageDialog(this,"远程启动指令已经发出!","系统提示",JOptionPane.INFORMATION_MESSAGE);

}catch(NumberFormatException nfe){

JOptionPane.showMessageDialog(this,"地址格式有错!"+nfe.getMessage(),"系统错误",JOptionPane.ERROR_MESSAGE);

}catch(IOException ioe){

JOptionPane.showMessageDialog(this,"网络通信出错!"+ioe.getMessage(),"系统错误",JOptionPane.ERROR_MESSAGE);

}

}

if(e.getSource()==ExitButton){

dispose();

System.exit(0);

}

}

public void itemStateChanged(ItemEvent e){

if(e.getSource()==MACList){

MACAddr.setText((String)MACList.getSelectedItem());

}

}

private int width,height;

private JLabel ListLabel,MACLabel,BroadcastLabel;

private Vector MACArray;

private JComboBox MACList;

private JTextField MACAddr;

private JTextField BroadcastAddr;

private int port;

private JButton OKButton,ExitButton;

private String datafile;

}

/*

* WakeLan.java

*

* Created on 2007年9月6日 下午9:05

*

* To change this template, choose Tools | Template Manager

* and open the template in the editor.

*/

package wakelan;

/**

*

* @author hyj

*/

import java.awt.*;

import javax.swing.*;

public class WakeLan {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

Font defaultFont=new Font("宋体",Font.PLAIN,16);

UIManager.put("Label.font",defaultFont);

UIManager.put("Button.font",defaultFont);

UIManager.put("TextField.font",defaultFont);

WakeFrame frame=new WakeFrame();

frame.setVisible(true);

}

}

java怎么实现远程关闭计算机,远程唤醒的做好了,远程关机的不知道该怎么做

有管理员权限吧,那用shutdown命令就可以了

shutdown -m \\192.168.0.10 -f -s -t 0

shutdown /? 看看帮助信息。

C:\Windows\system32shutdown /?

Usage: shutdown [/i | /l | /s | /r | /g | /a | /p | /h | /e] [/f]

[/m \\computer][/t xxx][/d [p|u:]xx:yy [/c "comment"]]

No args Display help. This is the same as typing /?.

/? Display help. This is the same as not typing any options.

/i Display the graphical user interface (GUI).

This must be the first option.

/l Log off. This cannot be used with /m or /d options.

/s Shutdown the computer.

/r Shutdown and restart the computer.

/g Shutdown and restart the computer. After the system is

rebooted, restart any registered applications.

/a Abort a system shutdown.

This can only be used during the time-out period.

/p Turn off the local computer with no time-out or warning.

Can be used with /d and /f options.

/h Hibernate the local computer.

Can be used with the /f option.

/e Document the reason for an unexpected shutdown of a computer.

/m \\computer Specify the target computer.

/t xxx Set the time-out period before shutdown to xxx seconds.

The valid range is 0-315360000 (10 years), with a default of 30.

If the timeout period is greater than 0, the /f parameter is

implied.

/c "comment" Comment on the reason for the restart or shutdown.

Maximum of 512 characters allowed.

/f Force running applications to close without forewarning users.

The /f parameter is implied when a value greater than 0 is

specified for the /t parameter.

/d [p|u:]xx:yy Provide the reason for the restart or shutdown.

p indicates that the restart or shutdown is planned.

u indicates that the reason is user defined.

If neither p nor u is specified the restart or shutdown is

unplanned.

xx is the major reason number (positive integer less than 256).

yy is the minor reason number (positive integer less than 65536).

关于java远程唤醒和远程唤醒命令的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。