Openfire 抓取packet
来源:互联网 发布:2017淘宝销售额 编辑:程序博客网 时间:2024/04/26 13:42
简述:
在openfire后台插件开发过程中,抓取通信往来的packet十分重要,而openfire的设计也考虑到了这一点,除了增加扩展性的Plugin接口,他也定义了一个包拦截器接口
PacketInterceptor ,本次试验就要用到这个抓包接口。
参考:
感谢两篇博客给了明确方向,
1, http://blog.csdn.net/ibm_hoojo/article/details/8736341
2, http://blog.csdn.net/dyflovexlp/article/details/4578929
步骤:
文件夹结构:
1. 首先添加Plugin, 这里先做一个没有后台界面的Plugin
Plugin.xml
<?xml version="1.0" encoding="UTF-8"?><plugin> <!-- Main plugin class 插件的全路径--> <class>com.anialy.openfire.chatwrapper.ChatWrapperPlugin</class> <!-- Plugin meta-data --> <name>ChatWrapperPlugin</name> <description>Chat Wrapper Plugin</description> <author>anialy</author> <version>1.0</version> <date>19/04/2013</date> <minServerVersion>3.7.2</minServerVersion> <licenseType>gpl</licenseType> <adminconsole> </adminconsole></plugin>
2. 之后是两个Java类文件
ChatWrapperPlugin.java
package com.anialy.openfire.chatwrapper;import java.io.File;import java.util.List;import org.jivesoftware.openfire.container.Plugin;import org.jivesoftware.openfire.container.PluginManager;import org.jivesoftware.openfire.interceptor.InterceptorManager;import org.jivesoftware.openfire.interceptor.PacketInterceptor;import org.jivesoftware.openfire.interceptor.PacketRejectedException;import org.jivesoftware.openfire.session.Session;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.xmpp.packet.Message;import org.xmpp.packet.Packet;import com.anialy.openfire.chatwrapper.intercepter.ChatWrapperInterceptor;public class ChatWrapperPlugin implements Plugin {private PacketInterceptor pktInterceptor = null;//openfire server维护的一个拦截器集合private InterceptorManager icpManager = InterceptorManager.getInstance();@Overridepublic void initializePlugin(PluginManager manager, File pluginDirectory) {System.out.println("安装 ChatWrapper 插件");pktInterceptor = new ChatWrapperInterceptor();icpManager.addInterceptor(pktInterceptor);}@Overridepublic void destroyPlugin() {System.out.println("卸载 ChatWrapper 插件");if(pktInterceptor != null){icpManager.removeInterceptor(pktInterceptor);}}}
ChatWrapperInterceptor.java
package com.anialy.openfire.chatwrapper.intercepter;import java.util.List;import org.jivesoftware.openfire.interceptor.PacketInterceptor;import org.jivesoftware.openfire.interceptor.PacketRejectedException;import org.jivesoftware.openfire.session.Session;import org.xmpp.packet.Message;import org.xmpp.packet.Packet;public class ChatWrapperInterceptor implements PacketInterceptor {@Overridepublic void interceptPacket(Packet packet, Session session,boolean incoming, boolean processed) throws PacketRejectedException {System.out.println("Intercept Packet ~~~~~~~~~~~~");Packet copyPacket = packet.createCopy();if(packet instanceof Message){Message message = (Message) copyPacket;// 一对一聊天,单人模式if (message.getType() == Message.Type.chat) {System.out.println("单人聊天信息:" + message.toXML());// 程序执行中;是否为结束或返回状态(是否是当前session用户发送消息)if (processed || !incoming) {return;}// 群聊天,多人模式} else if (message.getType() == Message.Type.groupchat) {List<?> els = message.getElement().elements("x");if (els != null && !els.isEmpty()) {System.out.println("群聊天信息:" + message.toXML());} else {System.out.println("群系统信息:" + message.toXML());} // 其他信息} else {System.out.println("其他信息:" + message.toXML());}}}}
输出:
1. 当单人聊天时:发送消息“你好呀”
Intercept Packet ~~~~~~~~~~~~单人聊天信息:<message id="qSFSM-94" to="tester2@anialy-pc/Spark 2.6.3" from="tester1@anialy-pc/Spark 2.6.3" type="chat"><body>你好呀</body><thread>fwXwHx</thread><x xmlns="jabber:x:event"><offline/><composing/></x></message>Intercept Packet ~~~~~~~~~~~~单人聊天信息:<message id="qSFSM-94" to="tester2@anialy-pc/Spark 2.6.3" from="tester1@anialy-pc/Spark 2.6.3" type="chat"><body>你好呀</body><thread>fwXwHx</thread><x xmlns="jabber:x:event"><offline/><composing/></x></message>Intercept Packet ~~~~~~~~~~~~单人聊天信息:<message id="qSFSM-94" to="tester2@anialy-pc/Spark 2.6.3" from="tester1@anialy-pc/Spark 2.6.3" type="chat"><body>你好呀</body><thread>fwXwHx</thread><x xmlns="jabber:x:event"><offline/><composing/></x></message>Intercept Packet ~~~~~~~~~~~~单人聊天信息:<message id="qSFSM-94" to="tester2@anialy-pc/Spark 2.6.3" from="tester1@anialy-pc/Spark 2.6.3" type="chat"><body>你好呀</body><thread>fwXwHx</thread><x xmlns="jabber:x:event"><offline/><composing/></x></message>
2. 当群聊时:
Intercept Packet ~~~~~~~~~~~~群聊天信息:<message id="qSFSM-77" to="测试聊天室@conference.anialy-pc" type="groupchat" from="tester1@anialy-pc/Spark 2.6.3"><body>阿斯蒂芬</body><x xmlns="jabber:x:event"><offline/><delivered/><displayed/><composing/></x></message>Intercept Packet ~~~~~~~~~~~~群聊天信息:<message id="qSFSM-77" to="tester1@anialy-pc/Spark 2.6.3" type="groupchat" from="测试聊天室@conference.anialy-pc/tester1"><body>阿斯蒂芬</body><x xmlns="jabber:x:event"><offline/><delivered/><displayed/><composing/></x></message>Intercept Packet ~~~~~~~~~~~~群聊天信息:<message id="qSFSM-77" to="tester1@anialy-pc/Spark 2.6.3" type="groupchat" from="测试聊天室@conference.anialy-pc/tester1"><body>阿斯蒂芬</body><x xmlns="jabber:x:event"><offline/><delivered/><displayed/><composing/></x></message>Intercept Packet ~~~~~~~~~~~~群聊天信息:<message id="qSFSM-77" to="tester1@anialy-pc/Spark 2.6.3" type="groupchat" from="测试聊天室@conference.anialy-pc/tester1"><body>阿斯蒂芬</body><x xmlns="jabber:x:event"><offline/><delivered/><displayed/><composing/></x></message>
小结:
有了PacketInterceptor,我们发现在服务器收发消息的时候我们可以做很多事情,比如对抓到的数据包做后台记录,又比如压缩数据包减少网络流量或是延时,这是值得继续做实验的
- Openfire 抓取packet
- packet
- 【openfire插件开发】packet分类路由(职责链模式yes or no)
- openfire
- openfire
- openfire
- openfire
- Openfire
- openfire
- OpenFire
- openfire
- openfire
- openfire
- 蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法 【原创,多图】
- 蓝牙4.0BLE cc2540 usb-dongle的 SmartRF Packet Sniffer 抓取数据方法
- 抓取
- 抓取
- Packet Sniffers
- ThreadLocal
- 正则表达式
- 遗传算法的java实现
- PLSQL Developer 9.如何设置查询返回所有纪录
- JTAG
- Openfire 抓取packet
- Oracle 函数 Translate 的用法
- UEditor使用快捷键
- easyui Layout 自动适应窗口大小
- Linux下查看CPU信息、机器型号等硬件信息命令
- 连接错误System.Net.Sockets.SocketException:由于系统缓冲区空间不足或列队已满,不能执行套接字上的操作
- Ext文本输入框:Ext.form.TextField属性汇总
- OCX的调试
- STOP BEING AFRAID OF FAILURE - The One Lesson Every Entrepreneur Should Learn