How to Analyze the Network Behaviors of IoT-enabled Devices Using Wireshark

Image for post
Image for post

1) Background

2) Preparations

2.1 Create a Device

Image for post
Image for post

2.2 Device Simulation Program

/**
* node aliyun-iot-device.js
*/
const mqtt = require('aliyun-iot-mqtt');
//设备身份三元组+区域
const options = {
"productKey": "设备PK",
"deviceName": "设备DN",
"deviceSecret": "设备Secret",
"regionId": "cn-shanghai"
};
//1.建立连接
const client = mqtt.getAliyunIotMqttClient(options);
//2.订阅主题
setTimeout(function() {
client.subscribe(`/${options.productKey}/${options.deviceName}/user/get`)
}, 3 * 1000);
//3.发布消息
setTimeout(function() {
client.publish(`/${options.productKey}/${options.deviceName}/user/update`, getPostData(),{qos:1});
}, 5 * 1000);
//4.关闭连接
setTimeout(function() {
client.end();
}, 8 * 1000);
function getPostData() {
const payloadJson = {
temperature: Math.floor((Math.random() * 20) + 10),
humidity: Math.floor((Math.random() * 20) + 10)
}
console.log("payloadJson " + JSON.stringify(payloadJson))
return JSON.stringify(payloadJson);

2.3 Capture Network Packets with Wireshark

Image for post
Image for post

2.4 Start the Device Simulation Program

Image for post
Image for post

3) Analysis of the Captured Packets

3.1 TCP Three-way Handshake

Image for post
Image for post

3.2 MQTT CONNECT Behavior

Image for post
Image for post
Image for post
Image for post

3.3 MQTT SUBSCRIBE Behavior

Image for post
Image for post
Image for post
Image for post

3.4 MQTT PUBLISH Behavior

Image for post
Image for post
Image for post
Image for post
Image for post
Image for post

3.5 MQTT DISCONNECT Behavior

Image for post
Image for post

3.6 TCP Four-way Handshake

Image for post
Image for post
Image for post
Image for post

4) Summary

5) Appendix

Image for post
Image for post

Original Source:

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store