首页 > 其他分享 >监听调试web service的好工具TCPMon

监听调试web service的好工具TCPMon

时间:2023-06-27 18:06:57浏览次数:44  
标签:web service int void 监控 new TCPMon buf man


一般的远程监控软件都是用c或者c++等语言开发的,而使用java如何来实现相同的功能呢。 

首先我们先介绍一下一个简单的远程监控程序的实现原理。 

功能一,远程屏幕监视 
(1) 必须要有监控端与被监控端,而且程序保持启动。 
(2) 被监控端获取本机的屏幕截屏发图给监控端。 
(3) 监控端在本地窗口中显示被监控端发送过来的图像。 
(4) (2)(3)步骤重复执行,这时在监控端即可实时监视到被监控端的桌面操作了。 

功能二,远程控制 
(1) 必须要有监控端与被监控端,而且程序保持启动。 
(2) 在监控端监视窗体上执行鼠标点击事件。 
(3) 记录步骤 (2)中的鼠标点击的坐标,及键值发送到被监控端。 
(4) 被监控接受鼠标坐标,及键值,然后再本地屏幕上模拟同样的点击动作。 

OK,现在看下具体的java与语言是如何实现上述功能的。 

使用java语言要实现截屏的功能就要依靠java类库中的一个有趣的类 
java.awt.Robot类【俗称Java机器人】了 


功能一,远程屏幕监视 
//『客户端』抓取屏幕快照GuiCamera.java



 


BufferedImage screenshot = 
    
                    (new Robot()).createScreenCapture( 
    
                            new Rectangle(0, 0, (int) size.getWidth(), 
    
                                          (int) size.getHeight()));



 

1. BufferedImage screenshot =  
2. new Robot()).createScreenCapture(  
3. new Rectangle(0, 0, (int) size.getWidth(),  
4. int) size.getHeight()));


//『客户端』发送快照 SendThread.java



 



image=gc.snapShot(); 
    
               //保存为临时文件 
    
               File file=new File("temp.png"); 
    
               FileOutputStream fileout=new FileOutputStream(file); 
    
               ImageIO.write(image,"png",fileout); 
    
               fileout.close(); 
    
                
    
               //读取图像 
    
               FileInputStream fileIn=new FileInputStream(file); 
    
               int len=(int)file.length(); 
    

              //建立字节数组 
    
               byte[] buf=new byte[len]; 
    
               fileIn.read(buf,0,len); 
    

               //发送 
    
               out.write(buf,0,len); 
    
               out.flush(); 
    
                
    
               //间隔500毫秒 
    
               Thread.sleep(500);


            



 


1. image=gc.snapShot();  
2. //保存为临时文件  
3. new File("temp.png");  
4. new FileOutputStream(file);  
5. "png",fileout);  
6.   fileout.close();  
7.     
8. //读取图像  
9. new FileInputStream(file);  
10. int len=(int)file.length();  
11.   
12. //建立字节数组  
13. byte[] buf=new byte[len];  
14. 0,len);  
15.   
16. //发送  
17. 0,len);  
18.   out.flush();  
19.     
20. //间隔500毫秒  
21. 500);



//『监控端』接受图像,Snap.java  
 

    public void run() { 
  
 while (flag) { 
  
                    byte[] buf = new byte[102400]; 
  
                    try { 
  

                        imgStream = new BufferedInputStream( 
  
                                socket.getInputStream()); 
  
                        imgStream.read(buf); 
  
                        ImageIcon icon = new ImageIcon(Toolkit. 
  
                                getDefaultToolkit(). 
  
                                createImage(buf)); 
  
                        lab.setIcon(icon); 
  

                        File file = new File("1.jpg"); 
  
                        FileOutputStream fileOut = new FileOutputStream(file); 
  
                        fileOut.write(buf); 
  
                        fileOut.close(); 
  

                        repaint(); 
  
                        setVisible(true); 
  
                        System.out.println("读取图象成功!"); 
  
                    } catch (Exception ex) { 
  
                        ex.printStackTrace(); 
  
                        flag = false; 
  
                    } 
  
                } 
  
                System.out.println("服务器停止"); 
  
            } 
  
}


 


1. public void run() {  
2. while (flag) {  
3. byte[] buf = new byte[102400];  
4. try {  
5.   
6. new BufferedInputStream(  
7.                                socket.getInputStream());  
8.                        imgStream.read(buf);  
9. new ImageIcon(Toolkit.  
10.                                getDefaultToolkit().  
11.                                createImage(buf));  
12.                        lab.setIcon(icon);  
13.   
14. new File("1.jpg");  
15. new FileOutputStream(file);  
16.                        fileOut.write(buf);  
17.                        fileOut.close();  
18.   
19.                        repaint();  
20. true);  
21. "读取图象成功!");  
22. catch (Exception ex) {  
23.                        ex.printStackTrace();  
24. false;  
25.                    }  
26.                }  
27. "服务器停止");  
28.            }



功能二,远程控制 


『监控端』记录鼠标操作Snap.java



//内部类,主要功能监听鼠标事件。记录坐标。 
  
class keyAdapet extends KeyAdapter 
  
    { //键盘监听适配器 
  
        public void keyTyped(KeyEvent e) { 
  

            if (e.getKeyChar() == 27) { //按ESC键 
  
                Object[] options = { 
  
                                   "确定", 
  
                                   "取消"}; 
  
                int n = JOptionPane.showOptionDialog(null, 
  
                        "是否退出程序?", 
  
                        "远程监控系统", 
  
                        JOptionPane.OK_CANCEL_OPTION, 
  
                        JOptionPane.QUESTION_MESSAGE, 
  
                        null, //don't use a custom Icon 
  
                        options, //the titles of buttons 
  
                        options[0]); 
  
                if (0 == n) { 
  
                    System.exit(0); 
  
                } 
  
            } 
  

        } 
  
    } 
  

       
  
        public void mouseClicked(MouseEvent e) { 
  

            System.out.println("双击了鼠标"); 
  
            int x = e.getX(); 
  
            int y = e.getY(); 
  
            if (tempSocket != null) { 
  
                new CommandMsg("2", tempSocket, x, y).start(); 
  
            } 
  
        } 
  

        public void mousePressed(MouseEvent e) { 
  
            if (e.BUTTON1 == MouseEvent.BUTTON1) { 
  
                System.out.println("你按了鼠标左键~~~~~~~~~~~"); 
  
                int x = e.getX(); 
  
                int y = e.getY(); 
  
                if (tempSocket != null) { 
  
                    new CommandMsg("3", tempSocket, x, y).start(); 
  
                } 
  
            } 
  
        } 
  

       ...... 
  
   }





 

1. //内部类,主要功能监听鼠标事件。记录坐标。  
2. class keyAdapet extends KeyAdapter  
3. //键盘监听适配器  
4. public void keyTyped(KeyEvent e) {  
5.   
6. if (e.getKeyChar() == 27) { //按ESC键  
7.                 Object[] options = {  
8. "确定",  
9. "取消"};  
10. int n = JOptionPane.showOptionDialog(null,  
11. "是否退出程序?",  
12. "远程监控系统",  
13.                         JOptionPane.OK_CANCEL_OPTION,  
14.                         JOptionPane.QUESTION_MESSAGE,  
15. null, //don't use a custom Icon  
16. //the titles of buttons  
17. 0]);  
18. if (0 == n) {  
19. 0);  
20.                 }  
21.             }  
22.   
23.         }  
24.     }  
25.   
26.         
27. public void mouseClicked(MouseEvent e) {  
28.   
29. "双击了鼠标");  
30. int x = e.getX();  
31. int y = e.getY();  
32. if (tempSocket != null) {  
33. new CommandMsg("2", tempSocket, x, y).start();  
34.             }  
35.         }  
36.   
37. public void mousePressed(MouseEvent e) {  
38. if (e.BUTTON1 == MouseEvent.BUTTON1) {  
39. "你按了鼠标左键~~~~~~~~~~~");  
40. int x = e.getX();  
41. int y = e.getY();  
42. if (tempSocket != null) {  
43. new CommandMsg("3", tempSocket, x, y).start();  
44.                 }  
45.             }  
46.         }  
47.   
48.        ......  
49.    }


『监控端』发送坐标Snap.java 



public void run() { 
  
                out.println(eventType + "," + x + "," + y); 
  
                out.flush(); 
  
}


 


1. public void run() {  
2. "," + x + "," + y);  
3.                 out.flush();  
4. }



『客户端』获取鼠标坐标后,在本机相同坐标位置模拟一个鼠标点击操作 Coop.java

public void run() {
        while (flag) {
            try {
                String s = in.readLine();
                decode(s);
                switch (method) {
                //这里的man实际也是Robot的一个实例。
                case 1:
                    man.mouseMove(x, y);
                    break;
                case 2:
                    man.mouseMove(x, y);
                    man.mousePress(InputEvent.BUTTON1_MASK);
                    man.mouseRelease(InputEvent.BUTTON1_MASK);
                    break;
                case 3:
                    man.mousePress(InputEvent.BUTTON1_MASK);
                    break;
                case 4:
                    man.mouseRelease(InputEvent.BUTTON1_MASK);
                    break;
                default:
                    break;
                }

            } catch (IOException exe) {
                ThreadInfo.CoopIsLive=false;
                flag=false;
                exe.printStackTrace();
            }
        }
    }



 


1. public void run() {  
2. while (flag) {  
3. try {  
4.                 String s = in.readLine();  
5.                 decode(s);  
6. switch (method) {  
7. //这里的man实际也是Robot的一个实例。  
8. case 1:  
9.                     man.mouseMove(x, y);  
10. break;  
11. case 2:  
12.                     man.mouseMove(x, y);  
13.                     man.mousePress(InputEvent.BUTTON1_MASK);  
14.                     man.mouseRelease(InputEvent.BUTTON1_MASK);  
15. break;  
16. case 3:  
17.                     man.mousePress(InputEvent.BUTTON1_MASK);  
18. break;  
19. case 4:  
20.                     man.mouseRelease(InputEvent.BUTTON1_MASK);  
21. break;  
22. default:  
23. break;  
24.                 }  
25.   
26. catch (IOException exe) {  
27. false;  
28. false;  
29.                 exe.printStackTrace();  
30.             }  
31.         }  
32.     }


 

代码的部分就介绍到这里,由于java语言的一些限制,本实例仅作为演示。有感兴趣的朋友可以下载附件中的程序做进一步参考。远程监控2.zip (227.9 KB)

 


标签:web,service,int,void,监控,new,TCPMon,buf,man
From: https://blog.51cto.com/nethub/6564727

相关文章

  • 什么是RESTful Web Service / webservice和restful的区别
    http://www.ruanyifeng.com/blog/2014/05/restful_api.htmlhttp://developer.51cto.com/art/200908/141825.htm 用Java技术创建RESTfulWeb服务http://www.ibm.com/developerworks/cn/web/wa-jaxrs/基于REST的Web服务:基础http://www.ibm.com/developerworks/cn/webservice......
  • 如何在.net6webapi中记录每次接口请求的日志
    为什么在软件设计中一定要有日志系统?在软件设计中日志模块是必不可少的一部分,可以帮助开发人员更好的了解程序的运行情况,提高软件的可靠性,安全性和性能,日志通常能帮我们解决如下问题:调试和故障排查:日志可以记录程序运行时的各种信息,包括错误,异常,警告等,方便开发人员在出现问题时......
  • WEB自动化-selenium-定位方式
    定位元素的时候可以修改JS样式来确定定位的元素是否正确#通过selenium修改JS属性,用来确定我定位的元素是什么?driver.execute_script("arguments[0].setAttribute('style',arguments[1]);",el,"border:2pxsolidgreen;"#边框,green绿色) ......
  • CTFer成长记录——Web专题·双写绕过
    一、题目链接http://a.y1ng.vip:1126/employeeswork/二、题意解析  访问该网址:  发现是一些不明觉厉的英文:  关于Y1ng公司所有员工的通知:  如果你认为你对自己的工作感到满意,你可以使用函数work_worthy()。  但是是否值得,只会由我的机器人PrecocedeMalingre来......
  • Spring中什么时候用@Resource,@service,及Spring注解@Component、@Repository、@Servic
    参考资料http://crabboy.iteye.com/blog/339840文章正文<context:annotation-config/> <context:component-scanbase-package=”com.eric.spring”> component-scan标签默认情况下自动扫描指定路径下的包(含所有子包),将带有@Component、@Repository、@Service、@Controller标签......
  • Webservice
    http://www.blogjava.net/zjhiphop/archive/2009/04/29/webservice.htmlhttp://m.blog.sina.com.cn/s/blog_7ba28b620100ti0j.html?sudaref=login.sina.com.cn#page=1     ......
  • CTFer成长记录——web专题·一句话木马
    一、题目链接http://a.y1ng.vip:1126/chopper/二、题意解析打开网址,发现网页提示:明显是一个一句话木马的语句,而且可以猜测网页后台已经有php木马文件,我们只需要连接上就行。三、解题步骤使用antSword等Webshell管理工具,来对该后门程序进行链接:这里用antSword,复制该网页的域......
  • 软件测试|web自动化测试神器playwright教程(三十四)
    前言selenium有一个爬虫特别喜欢的功能,就是driver.page_source功能,它可以打印整个html页面的内容,我们可以从整个页面的内容中提取出我们想要的内容,playwright同样支持打印整个html页面的内容。获取更多技术资料,请点击!获取完整页面html内容playwright提供了page.content()方法来获取......
  • 功能测试——web功能测试点
    WEB测试方法总结-笔记一、输入框1、字符型输入框:(1)字符型输入框:英文全角、英文半角、数字、空或者空格、特殊字符“~!@#¥%……&*?[]{}”特别要注意单引号和&符号。禁止直接输入特殊字符时,使用“粘贴、拷贝”功能尝试输入。(2)长度检查:最小长度、最大长度、最小长度-1、最大长度+1、输入超......
  • web.xml
    <?xmlversion="1.0"encoding="UTF-8"?><web-appxmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.o......