{"id":383,"date":"2025-08-17T16:55:29","date_gmt":"2025-08-17T08:55:29","guid":{"rendered":"http:\/\/yangnanbei.top\/?p=383"},"modified":"2025-08-24T16:18:47","modified_gmt":"2025-08-24T08:18:47","slug":"383","status":"publish","type":"post","link":"http:\/\/yangnanbei.top\/index.php\/2025\/08\/17\/383\/","title":{"rendered":"nbEasyTshark 05-08 \u5b9e\u65f6\u83b7\u53d6\u7f51\u5361\u6570\u636e"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">05 \u83b7\u53d6\u5730\u7406\u4fe1\u606f<\/h2>\n\n\n\n<p>\u2014\u2014\u975e\u590d\u5415\u8499\u4e4b\u4e09\u65e5\uff0c\u4f46\u89c1\u695a\u5e84\u4e4b\u98de\u9e23\u3002<\/p>\n\n\n\n<p>wireshark\u4e2d\u662f\u6ca1\u6709\u83b7\u53d6\u5730\u7406\u4fe1\u606f\u529f\u80fd\u7684\uff0c\u8fd9\u7b97\u662f\u4e00\u4e2a\u65b0future<\/p>\n\n\n\n<p>\u6211\u4eec\u4f7f\u7528\u5f00\u6e90\u7684\u6570\u636e\u5e93ip2region\u6765\u505a\u3002<\/p>\n\n\n\n<p>\u9879\u76ee\u5730\u5740\uff1ahttps:\/\/github.com\/lionsoul2014\/ip2region<\/p>\n\n\n\n<p>\u6211\u4eec\u80fd\u62ff\u5230\u4e00\u4e2aip2region.xdb\u6587\u4ef6\uff0c\u5982\u679c\u8981\u4f7f\u7528\u8fd9\u7c7b\u4fe1\u606f\u5e93\u6587\u4ef6\uff0c\u9996\u5148\u5f97\u52a0\u8f7d\u5b83<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>xdb_search_t searcher(\"ip2region\/ip2region.xdb\");\nsearcher.init_content();<\/code><\/pre>\n\n\n\n<p>\u5199\u4e2a\u5c0fdemo\u6d4b\u8bd5\u4e00\u4e0b<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>#include \"..\/third_library\/ip2region\/xdb_search.h\"\n#include &lt;string>\n#include &lt;iostream>\n\nint main() {\n    xdb_search_t searcher(\"..\/third_library\/ip2region\/ip2region.xdb\");\n    searcher.init_content();\n\n    std::string ip = \"211.21.92.114\";\n    std::string location = searcher.search(ip);\n\n    std::cout &lt;&lt; ip &lt;&lt; \": \" &lt;&lt; location &lt;&lt; std::endl;\n\n    return 0;\n}\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">#include<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">..\/third_library\/ip2region\/xdb_search.h<\/span><span style=\"color: #DEE492\">&quot;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">#include<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&lt;<\/span><span style=\"color: #E7EE98\">string<\/span><span style=\"color: #DEE492\">&gt;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">#include<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&lt;<\/span><span style=\"color: #E7EE98\">iostream<\/span><span style=\"color: #DEE492\">&gt;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">main<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #97E1F1; font-style: italic\">xdb_search_t<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">searcher<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">..\/third_library\/ip2region\/ip2region.xdb<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    searcher.<\/span><span style=\"color: #62E884\">init_content<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string ip <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">211.21.92.114<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string location <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> searcher.<\/span><span style=\"color: #62E884\">search<\/span><span style=\"color: #F6F6F4\">(ip);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">cout <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> ip <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">: <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> location <\/span><span style=\"color: #F286C4\">&lt;&lt;<\/span><span style=\"color: #F6F6F4\"> std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">endl;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p>compile:<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>g++ -std=c++14 .\\02_ip2region.cpp<\/p>\n\n\n\n<p>..\\third_library\\ip2region\\xdb_search.cc -o ip2region_test.exe -lws2_32<\/p>\n<\/blockquote>\n\n\n\n<p>\u8f93\u51fa\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>211.21.92.114: \u4e2d\u56fd|0|\u53f0\u6e7e\u7701|0|\u4e2d\u534e\u7535\u4fe1<\/p>\n<\/blockquote>\n\n\n\n<p>\u597d\u4f7f~<\/p>\n\n\n\n<p>region\u7684\u683c\u5f0f\u662f\u56fa\u5b9a\u7684\uff1a\u56fd\u5bb6 | \u533a\u57df | \u7701\u4efd | \u57ce\u5e02 | ISP<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5f52\u5c5e\u5730\u683c\u5f0f\u5316<\/h3>\n\n\n\n<p>\u65e2\u7136\u8981\u7528\u5230\u7b2c\u4e09\u65b9\u5e93\uff0c\u90a3\u4e48\u5730\u7406\u4fe1\u606f\u76f8\u5173\u7684\u529f\u80fd\u5e94\u5c01\u88c5\u6210\u4e00\u4e2a\u5de5\u5177\u7c7b\u3002ip2region_util;<\/p>\n\n\n\n<p>\u4e4b\u540e\u6211\u4eec\u7684packet\u4fe1\u606f\u8f93\u51fa\u65f6\u9700\u8981\u589e\u52a0\u6e90ip\u548c\u76ee\u7684ip\u7684\u5f52\u5c5e\u4fe1\u606f\u3002<\/p>\n\n\n\n<p>\u6548\u679c\u5982\u56fe\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-7.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"994\" height=\"520\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-7.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-388\"  sizes=\"(max-width: 994px) 100vw, 994px\" \/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">06 \u9762\u5411\u5bf9\u8c61\u5c01\u88c5\uff0c\u6dfb\u52a0\u65e5\u5fd7\u529f\u80fd<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">TsharkManager\u5c01\u88c5<\/h3>\n\n\n\n<p>\u4e3a\u4e86\u65b9\u4fbf\u7ef4\u62a4\uff0c\u5c06\u4e0etshark\u6709\u5173\u7684\u64cd\u4f5c\u90fd\u5c01\u88c5\u6210<code>TsharkManager<\/code>\u7c7b\u3002<\/p>\n\n\n\n<p>\u5728visual studio\u4e2d\uff0c\u53f3\u952e\u9879\u76ee-&gt;\u6dfb\u52a0-&gt;\u7c7b\uff0c\u6dfb\u52a0TsharkManager\u3002<\/p>\n\n\n\n<p>\u5230\u76ee\u524d\u4e3a\u6b62\uff0c\u6211\u4eec\u6709\u5173tshark\u7684\u64cd\u4f5c\u90fd\u5c01\u88c5\u5230<code>TsharkManager<\/code>\u7c7b\u4e2d<\/p>\n\n\n\n<p>\u6211\u4eec\u4e4b\u524d\u505a\u4e86\u54ea\u4e9b\u64cd\u4f5c\u5462\uff1f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6211\u4eec\u53ef\u4ee5\u8bfb\u53d6\u79bb\u7ebf\u6587\u4ef6\u7684\u6570\u636e\uff0c\u9010\u884c\u89e3\u6790<\/li>\n\n\n\n<li>\u6211\u4eec\u53ef\u4ee5\u5c06\u8bfb\u53d6\u7684\u6570\u636e\u4fdd\u5b58\u5728\u6570\u636e\u7ed3\u6784\u4e2d\uff0c\u5728\u9700\u8981\u7684\u65f6\u5019\u53d6\u7528<\/li>\n<\/ul>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u53ef\u4ee5\u5c01\u88c5\u51fa\u4ee5\u4e0b\u7c7b\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>class TsharkManager\n{\npublic:\n    TsharkManager(std::string workDir);\n    ~TsharkManager();\n\n    bool analysisFile(std::string filePath);\n\n    void printAllPacket();\n\n    bool getPacketHexData(uint32_t frameNumber, std::vector&lt;unsigned char>&amp; data);\n\nprivate:\n    bool parseLine(std::string line, std::shared_ptr&lt;Packet> packet);\n\nprivate:\n    std::string tsharkPath;\n    std::string currentFilePath;\n\n    IP2RegionUtil ip2regionUtil;\n\n    std::unordered_map&lt;uint32_t, std::shared_ptr&lt;Packet>> allPackets;\n};<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">class<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1\">TsharkManager<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">{<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #62E884\">TsharkManager<\/span><span style=\"color: #F6F6F4\">(std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">string<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">workDir<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #62E884\">~TsharkManager<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">bool<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">analysisFile<\/span><span style=\"color: #F6F6F4\">(std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">string<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">filePath<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">void<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">printAllPacket<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">bool<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">getPacketHexData<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #F286C4\">uint32_t<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">frameNumber<\/span><span style=\"color: #F6F6F4\">, std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">vector<\/span><span style=\"color: #F6F6F4\">&lt;<\/span><span style=\"color: #F286C4\">unsigned<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">char<\/span><span style=\"color: #F6F6F4\">&gt;<\/span><span style=\"color: #F286C4\">&amp;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">data<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">bool<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">parseLine<\/span><span style=\"color: #F6F6F4\">(std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">string<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">line<\/span><span style=\"color: #F6F6F4\">, std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">shared_ptr<\/span><span style=\"color: #F6F6F4\">&lt;<\/span><span style=\"color: #97E1F1; font-style: italic\">Packet<\/span><span style=\"color: #F6F6F4\">&gt; <\/span><span style=\"color: #FFB86C; font-style: italic\">packet<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">private:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string tsharkPath;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">string currentFilePath;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    IP2RegionUtil ip2regionUtil;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">unordered_map<\/span><span style=\"color: #F286C4\">&lt;uint32_t<\/span><span style=\"color: #F6F6F4\">, std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">shared_ptr<\/span><span style=\"color: #F286C4\">&lt;<\/span><span style=\"color: #F6F6F4\">Packet<\/span><span style=\"color: #F286C4\">&gt;&gt;<\/span><span style=\"color: #F6F6F4\"> allPackets;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">};<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u65e5\u5fd7\u6846\u67b6loguru<\/h3>\n\n\n\n<p>\u5f53\u7a0b\u5e8f\u5177\u6709\u4e00\u5b9a\u89c4\u6a21\u540e\uff0c\u4fbf\u9700\u8981\u5f15\u5165\u65e5\u5fd7\u6a21\u5757\u3002\u8fd9\u6837\u505a\u6709\u5982\u4e0b\u597d\u5904\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u53ef\u4ee5\u5c06\u65e5\u5fd7\u6309\u7167\u4e25\u91cd\u7a0b\u5ea6\u5206\u7ea7\uff0c\u5e38\u89c1\u7684\u65e5\u5fd7\u5206\u7ea7\u65b9\u5f0f\u5982\u4e0b\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>debug: \u8f83\u4e3averbose\u7684\u4fe1\u606f<\/li>\n\n\n\n<li>info: \u5f80\u5f80\u662f\u67d0\u4e2a\u6a21\u5757\u91cd\u8981\u529f\u80fd\u7684\u8be6\u7ec6\u4fe1\u606f<\/li>\n\n\n\n<li>notice\/warning\uff1a\u9700\u8981\u6ce8\u610f\u7684\u4fe1\u606f<\/li>\n\n\n\n<li>error:\u9519\u8bef\uff01<\/li>\n<\/ul>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>c++\u4e2d\u7684std::cout\u5728\u591a\u7ebf\u7a0b\u73af\u5883\u4e0b\u5bb9\u6613\u6df7\u4e71<\/li>\n\n\n\n<li>\u7f3a\u4e4f\u65f6\u95f4\u6233\u548c\u6587\u4ef6\u4fe1\u606f\uff0c\u8c03\u8bd5\u65f6\u4e0d\u76f4\u89c2<\/li>\n\n\n\n<li>\u6027\u80fd\u95ee\u9898<\/li>\n<\/ol>\n\n\n\n<p>\u4ee5\u4e0a\uff0c\u6bd4\u8d77\u81ea\u5df1\u9020\u4e00\u4e2a\u65e5\u5fd7\u8f6e\u5b50\uff0c\u6211\u4eec\u9009\u62e9<code>loguru<\/code>\u4f5c\u4e3a\u7b2c\u4e09\u65b9\u65e5\u5fd7\u5e93\u3002<\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/emilk\/loguru\">GitHub &#8211; emilk\/loguru: A lightweight C++ logging library<\/a><\/p>\n\n\n\n<p>\u521d\u59cb\u5316\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>    loguru::init(argc, argv);\n    loguru::add_file(\"nb_easy_tshark.log\", loguru::Append, loguru::Verbosity_MAX);<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F6F6F4\">    loguru<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #62E884\">init<\/span><span style=\"color: #F6F6F4\">(argc, argv);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    loguru<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #62E884\">add_file<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">nb_easy_tshark.log<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">, loguru<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">Append, loguru<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">Verbosity_MAX);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u5404\u7ea7\u522b\u6253\u5370\uff1a<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly> LOG_F(ERROR, \"Failed to open file: %s\", packet_file.c_str());\n LOG_F(WARNING, \"Failed to open file: %s\", packet_file.c_str());\n LOG_F(INFO, \"Failed to open file: %s\", packet_file.c_str());<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">LOG_F<\/span><span style=\"color: #F6F6F4\">(ERROR, <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Failed to open file: <\/span><span style=\"color: #BF9EEE\">%s<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">, packet_file.<\/span><span style=\"color: #62E884\">c_str<\/span><span style=\"color: #F6F6F4\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">LOG_F<\/span><span style=\"color: #F6F6F4\">(WARNING, <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Failed to open file: <\/span><span style=\"color: #BF9EEE\">%s<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">, packet_file.<\/span><span style=\"color: #62E884\">c_str<\/span><span style=\"color: #F6F6F4\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">LOG_F<\/span><span style=\"color: #F6F6F4\">(INFO, <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Failed to open file: <\/span><span style=\"color: #BF9EEE\">%s<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">, packet_file.<\/span><span style=\"color: #62E884\">c_str<\/span><span style=\"color: #F6F6F4\">());<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">07 \u83b7\u53d6\u7f16\u7a0b\u7f51\u5361\u7684\u679a\u4e3e<\/h2>\n\n\n\n<p>\u73b0\u5728\u6211\u4eec\u77e5\u9053<code>tshark -D<\/code>\u547d\u4ee4\u53ef\u4ee5\u83b7\u53d6\u5f53\u524d\u7cfb\u7edf\u4e2d\u7684\u7f51\u5361\u679a\u4e3e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-8.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"663\" height=\"305\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-8.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-389\"  sizes=\"(max-width: 663px) 100vw, 663px\" \/><\/div><\/figure>\n\n\n\n<p>\u5bf9\u6bd4\u4e00\u4e0b Wireshark\u4e0a\u7684\u7f51\u5361\u540d\u5427\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-9.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"529\" height=\"248\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-9.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-390\"  sizes=\"(max-width: 529px) 100vw, 529px\" \/><\/div><\/figure>\n\n\n\n<p>\u82e5\u662f\u5bf9\u6807wireshark\uff0c\u5b9e\u9645\u4e0a\u6211\u4eec\u60f3\u8981\u7684\u662f\u7f51\u5361\u540d\u4e2d\u6700\u540e()\u91cc\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u8fd9\u91cc\u9700\u8981\u505a\u4e00\u4e9b\u5b57\u7b26\u4e32\u64cd\u4f5c<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u8fc7\u6ee4\u6389\u6211\u4eec\u4e0d\u9700\u8981\u7684\u7f51\u5361\uff0c\u5982ciscodump,etwdump&#8230;<\/li>\n\n\n\n<li>\u83b7\u53d6<code>tshark -D<\/code>\u7f51\u5361\u7684\u6253\u5370\uff0c\u800c\u540e\u5f97\u5230id\uff0cname\uff0c\u548cremark<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>    \/* get name and remark\n     * e.g: 6. \\Device\\NPF_{FFCB4D95-E737-4DCA-B016-522C9BA641B5} (WLAN)\n     * id:6\n     * name:\\Device\\NPF_{FFCB4D95-E737-4DCA-B016-522C9BA641B5}\n     * remark:WLAN\n     *\/<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #7B7F8B\">    \/* get name and remark<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">     * e.g: 6. \\Device\\NPF_{FFCB4D95-E737-4DCA-B016-522C9BA641B5} (WLAN)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">     * id:6<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">     * name:\\Device\\NPF_{FFCB4D95-E737-4DCA-B016-522C9BA641B5}<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">     * remark:WLAN<\/span><\/span>\n<span class=\"line\"><span style=\"color: #7B7F8B\">     *\/<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u6700\u7ec8\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-10.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"774\" height=\"183\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-10.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-391\"  sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/div><\/figure>\n\n\n\n<p>bingo~<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">08 \u7f51\u5361\u6570\u636e\u5305\u91c7\u96c6\u5206\u6790<\/h2>\n\n\n\n<p>\u6211\u4eec\u4e4b\u524d\u7684\u5206\u6790\u90fd\u662f\u57fa\u4e8e\u79bb\u7ebf\u6570\u636e\u5305\u7684\u5206\u6790\uff0c\u800c\u73b0\u5728\u6211\u4eec\u9700\u8981\u548cwireshark\u4e00\u6837\uff0c\u53ef\u4ee5\u5b9e\u65f6\u5206\u6790\u4ece\u7f51\u5361\u4e0a\u6293\u5230\u7684\u6570\u636e\u5305\u7684\u6570\u636e\u3002<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>tshark -i WLAN<\/p>\n<\/blockquote>\n\n\n\n<figure class=\"wp-block-image size-large\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-11-1024x249.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"249\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-11-1024x249.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-392\"  sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/div><\/figure>\n\n\n\n<p>tashark \u4f1a\u6293\u53d6\u7f51\u5361\u4e0a\u6d41\u7ecf\u7684\u6570\u636e\u62a5\u6587\uff0c\u5e76\u52a0\u4ee5\u6253\u5370\u3002<\/p>\n\n\n\n<p>\u65e2\u7136\u6211\u4eec\u8981\u5bf9\u6570\u636e\u5305\u8fdb\u884c\u5b9e\u65f6\u7684\u5206\u6790\uff0c\u90a3\u4e48\u6211\u4eec\u4e5f\u5c31\u9700\u8981\u6269\u5c55<code>TsharkManager<\/code>\u7684\u7c7b\u51fd\u6570<\/p>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>public:\n    bool startCapture(std::string adapterName);\n    bool stopCapture();<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">public:<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">bool<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">startCapture<\/span><span style=\"color: #F6F6F4\">(std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">string<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">adapterName<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">bool<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">stopCapture<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u4f7f\u7528\u591a\u7ebf\u7a0b\u6293\u5305<\/h3>\n\n\n\n<p>\u65b0\u5efa\u4e00\u4e2a\u7ebf\u7a0b\u7528\u4e8e\u5b9e\u65f6\u6293\u5305.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6570\u636e\u9762\uff1a\u5b9e\u65f6\u6293\u5305<\/li>\n\n\n\n<li>\u7ba1\u7406\u9762\uff1a\u63a7\u5236\u76f8\u5173<\/li>\n<\/ul>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>bool TsharkManager::startCapture(std::string adapterName) {\n    LOG_F(INFO, \"start to capture, adapterName %s\", adapterName.c_str());\n    stopFlag = false;\n    captureWorkerThread =  std::make_shared&lt;std::thread>(&amp;TsharkManager::captureWorkerThreadEntry,\n        this, \"\\\"\" + adapterName + \"\\\"\");\n    return true;\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">bool<\/span><span style=\"color: #F6F6F4\"> TsharkManager<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #62E884\">startCapture<\/span><span style=\"color: #F6F6F4\">(std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">string<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">adapterName<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #62E884\">LOG_F<\/span><span style=\"color: #F6F6F4\">(INFO, <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">start to capture, adapterName <\/span><span style=\"color: #BF9EEE\">%s<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">, adapterName.<\/span><span style=\"color: #62E884\">c_str<\/span><span style=\"color: #F6F6F4\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    stopFlag <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">false<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    captureWorkerThread <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\">  std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #62E884\">make_shared<\/span><span style=\"color: #F6F6F4\">&lt;std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">thread<\/span><span style=\"color: #F6F6F4\">&gt;(<\/span><span style=\"color: #F286C4\">&amp;<\/span><span style=\"color: #F6F6F4\">TsharkManager<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #F6F6F4\">captureWorkerThreadEntry,<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #BF9EEE; font-style: italic\">this<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F286C4\">\\&quot;<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">+<\/span><span style=\"color: #F6F6F4\"> adapterName <\/span><span style=\"color: #F286C4\">+<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F286C4\">\\&quot;<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">true<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u5f00\u59cb\u6293\u5305<\/h3>\n\n\n\n<p>\u6211\u4eec\u4e4b\u524d\u5b9e\u73b0\u4e86\u5206\u6790\u79bb\u7ebf\u6570\u636e\u5305\u7684\u51fd\u6570 <code>analysisFile<\/code>, \u73b0\u5728\u53ea\u9700\u8981\u7a0d\u5fae\u6539\u52a8\u4e00\u4e0b\u5c31\u80fd\u5b9e\u73b0\u5b9e\u65bd\u6293\u53d6\u6570\u636e\u5305\u7684\u529f\u80fd\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>tshark\u7684\u53c2\u6570\uff0c\u7531<code>-r<\/code>\u6539\u4e3a<code>-i<\/code> adapter. \u8868\u793a\u91c7\u96c6\u7f51\u5361\u6570\u636e<\/li>\n\n\n\n<li>\u589e\u52a0\u4e00\u4e9b\u53c2\u6570\uff1a\n<ol class=\"wp-block-list\">\n<li><code>-w<\/code>\uff1a\u6307\u5b9a\u4fdd\u5b58\u6570\u636e\u8868<\/li>\n\n\n\n<li><code>-f<\/code>: \u6307\u5b9a\u4fdd\u5b58\u4e3apcap\u683c\u5f0f<\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>\u5728while\u5faa\u73af\u4e2d\u589e\u52a0\u4e86stopFlag\u3002<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">\u505c\u6b62\u6293\u5305<\/h3>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>bool TsharkManager::stopCapture() {\n    LOG_F(INFO, \"now stop capture pcap\");\n    stopFlag = true;\n    captureWorkerThread->join();\n\n    return true;\n}<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">bool<\/span><span style=\"color: #F6F6F4\"> TsharkManager<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #62E884\">stopCapture<\/span><span style=\"color: #F6F6F4\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #62E884\">LOG_F<\/span><span style=\"color: #F6F6F4\">(INFO, <\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">now stop capture pcap<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    stopFlag <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">true<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    captureWorkerThread<\/span><span style=\"color: #F286C4\">-&gt;<\/span><span style=\"color: #62E884\">join<\/span><span style=\"color: #F6F6F4\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">true<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">}<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u800c\u540e\u4fee\u6539main\u51fd\u6570\u9002\u914d\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u5b9e\u65f6\u6293\u5305\u540e\u6253\u5370\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-12.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"963\" height=\"135\" data-original=\"http:\/\/yangnanbei.top\/wp-content\/uploads\/2025\/08\/image-12.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-393\"  sizes=\"(max-width: 963px) 100vw, 963px\" \/><\/div><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u65e0\u6570\u636e\u65f6\u5982\u4f55\u9000\u51fa\uff1f<\/h3>\n\n\n\n<p>\u5982\u679c\u7f51\u5361\u4e00\u76f4\u6ca1\u6709\u6570\u636e\u5305\uff0c\u90a3\u4e48\u5faa\u73af\u91cc\u7684fgets\u4f1a\u4e00\u76f4\u963b\u585e\u4e0d\u8fd4\u56de\uff0c\u6240\u4ee5\u4e3b\u7ebf\u7a0b\u53bb<code>join<\/code>\u5b83\u7684\u65f6\u5019\u4f1a\u4e00\u76f4\u7b49\u5f85\uff0c\u7a0b\u5e8f\u4f1a\u5361\u6b7b\uff0c\u9664\u975e\u6211\u4eec\u5f3a\u5236\u6740\u6b7b\u8fdb\u7a0b\u3002<\/p>\n\n\n\n<p>\u5982\u4f55\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff1a<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u53ef\u4ee5\u4f7f\u7528\u975e\u963b\u585eio\u548cselect\/poll\uff0c\u53d1\u73b0\u6709\u6570\u636e\u5230\u6765\u65f6\u624d\u4f7f\u7528fget\u53bb\u5c1d\u8bd5\u8bfb\u53d6<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>volatile int running = 1;\n\nvoid* data_thread_func(void* arg) {\n    FILE* pipe = (FILE*)arg;\n    int fd = fileno(pipe);\n    \n    int flags = fcntl(fd, F_GETFL, 0);\n    fcntl(fd, F_SETFL, flags | O_NONBLOCK);\n    \n    char buffer&#91;1024&#93;;\n    fd_set readfds;\n    struct timeval timeout;\n    \n    while (running) {\n        FD_ZERO(&amp;readfds);\n        FD_SET(fd, &amp;readfds);\n        \n        timeout.tv_sec = 0;\n        timeout.tv_usec = 100000;\n        \n        int result = select(fd + 1, &amp;readfds, NULL, NULL, &amp;timeout);\n        \n        if (result > 0 &amp;&amp; FD_ISSET(fd, &amp;readfds)) {\n            if (fgets(buffer, sizeof(buffer), pipe) != NULL) {\n                printf(\"Received: %s\", buffer);\n            }\n        } else if (result == 0) {\n            continue;\n        } else {\n            perror(\"select\");\n            break;\n        }\n    }\n    \n    fclose(pipe);\n    return NULL;\n}\n<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F286C4\">volatile<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> running <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">1<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F286C4\">void*<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">data_thread_func<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #F286C4\">void*<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">arg<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    FILE<\/span><span style=\"color: #F286C4\">*<\/span><span style=\"color: #F6F6F4\"> pipe <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> (FILE<\/span><span style=\"color: #F286C4\">*<\/span><span style=\"color: #F6F6F4\">)arg;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> fd <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">fileno<\/span><span style=\"color: #F6F6F4\">(pipe);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> flags <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">fcntl<\/span><span style=\"color: #F6F6F4\">(fd, F_GETFL, <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #62E884\">fcntl<\/span><span style=\"color: #F6F6F4\">(fd, F_SETFL, flags <\/span><span style=\"color: #F286C4\">|<\/span><span style=\"color: #F6F6F4\"> O_NONBLOCK);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">char<\/span><span style=\"color: #F6F6F4\"> buffer&#91;<\/span><span style=\"color: #BF9EEE\">1024<\/span><span style=\"color: #F6F6F4\">&#93;;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    fd_set readfds;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">struct<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">timeval<\/span><span style=\"color: #F6F6F4\"> timeout;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">while<\/span><span style=\"color: #F6F6F4\"> (running) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #62E884\">FD_ZERO<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #F286C4\">&amp;<\/span><span style=\"color: #F6F6F4\">readfds);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #62E884\">FD_SET<\/span><span style=\"color: #F6F6F4\">(fd, <\/span><span style=\"color: #F286C4\">&amp;<\/span><span style=\"color: #F6F6F4\">readfds);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        timeout.tv_sec <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        timeout.tv_usec <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">100000<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> result <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">select<\/span><span style=\"color: #F6F6F4\">(fd <\/span><span style=\"color: #F286C4\">+<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">1<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #F286C4\">&amp;<\/span><span style=\"color: #F6F6F4\">readfds, <\/span><span style=\"color: #BF9EEE\">NULL<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #BF9EEE\">NULL<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #F286C4\">&amp;<\/span><span style=\"color: #F6F6F4\">timeout);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        <\/span><span style=\"color: #F286C4\">if<\/span><span style=\"color: #F6F6F4\"> (result <\/span><span style=\"color: #F286C4\">&gt;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">&amp;&amp;<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">FD_ISSET<\/span><span style=\"color: #F6F6F4\">(fd, <\/span><span style=\"color: #F286C4\">&amp;<\/span><span style=\"color: #F6F6F4\">readfds)) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">            <\/span><span style=\"color: #F286C4\">if<\/span><span style=\"color: #F6F6F4\"> (<\/span><span style=\"color: #62E884\">fgets<\/span><span style=\"color: #F6F6F4\">(buffer, <\/span><span style=\"color: #F286C4\">sizeof<\/span><span style=\"color: #F6F6F4\">(buffer), pipe) <\/span><span style=\"color: #F286C4\">!=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">NULL<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">                <\/span><span style=\"color: #62E884\">printf<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">Received: <\/span><span style=\"color: #BF9EEE\">%s<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">, buffer);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">            }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        } <\/span><span style=\"color: #F286C4\">else<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">if<\/span><span style=\"color: #F6F6F4\"> (result <\/span><span style=\"color: #F286C4\">==<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">0<\/span><span style=\"color: #F6F6F4\">) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">            <\/span><span style=\"color: #F286C4\">continue<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        } <\/span><span style=\"color: #F286C4\">else<\/span><span style=\"color: #F6F6F4\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">            <\/span><span style=\"color: #62E884\">perror<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #E7EE98\">select<\/span><span style=\"color: #DEE492\">&quot;<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">            <\/span><span style=\"color: #F286C4\">break<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">        }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    }<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #62E884\">fclose<\/span><span style=\"color: #F6F6F4\">(pipe);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">return<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">NULL<\/span><span style=\"color: #F6F6F4\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>\u65e2\u7136\u65e0\u6d41\u91cf\u65f6fgets\u4f1a\u963b\u585e\uff0c\u90a3\u4e48\u9996\u5148\u786e\u8ba4\u4e0bfgets\u4ec0\u4e48\u65f6\u5019\u4f1a\u6b63\u5e38\u8fd4\u56de\uff1f<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8bfb\u5230\u6362\u884c\u7b26<code>\\n<\/code>\uff0c\u6b64\u65f6\u6362\u884c\u7b26\u4e5f\u4f1a\u88ab\u5305\u542b\u5728\u8fd4\u56de\u7684\u5b57\u7b26\u4e32\u4e2d\u3002<\/li>\n\n\n\n<li>\u8bfb\u5230\u6307\u5b9a\u7684\u5b57\u7b26\u6570<code>n-1<\/code>\uff0c\u5e76\u81ea\u52a8\u5728\u672b\u5c3e\u52a0\u4e0a\u7a7a\u5b57\u7b26<code>\\0<\/code>\u3002<\/li>\n\n\n\n<li>\u5230\u8fbe\u6587\u4ef6\u672b\u5c3e<code>EOF<\/code>.<\/li>\n<\/ul>\n\n\n\n<p>\u56e0\u4e3a\u6ca1\u6709\u6570\u636e\uff0c\u6240\u4ee5\u524d\u4e24\u79cd\u90fd\u4e0d\u6ee1\u8db3\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528kill tshark\u8fdb\u7a0b\u7684\u65b9\u5f0f\uff0c\u6740\u6b7b\u540epipe\u5c31\u4f1a\u65ad\u5f00\uff0cfgets\u4f1a\u5230\u8fbeEOF\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">kill tshark<\/h4>\n\n\n\n<p>\u8981\u6740\u6b7btshark\uff0c\u5c31\u9700\u8981<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>\u627e\u5230tshark\u7684pid<\/li>\n\n\n\n<li>\u5c01\u88c5kill\u7684\u51fd\u6570(win\/linux \u53cc\u5e73\u53f0)<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#f6f6f4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span style=\"display:block;padding:16px 0 0 16px;margin-bottom:-1px;width:100%;text-align:left;background-color:#282A36\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"54\" height=\"14\" viewBox=\"0 0 54 14\"><g fill=\"none\" fill-rule=\"evenodd\" transform=\"translate(1 1)\"><circle cx=\"6\" cy=\"6\" r=\"6\" fill=\"#FF5F56\" stroke=\"#E0443E\" stroke-width=\".5\"><\/circle><circle cx=\"26\" cy=\"6\" r=\"6\" fill=\"#FFBD2E\" stroke=\"#DEA123\" stroke-width=\".5\"><\/circle><circle cx=\"46\" cy=\"6\" r=\"6\" fill=\"#27C93F\" stroke=\"#1AAB29\" stroke-width=\".5\"><\/circle><\/g><\/svg><\/span><span role=\"button\" tabindex=\"0\" style=\"color:#f6f6f4;display:none\" aria-label=\"\u590d\u5236\" class=\"code-block-pro-copy-button\"><pre class=\"code-block-pro-copy-button-pre\" aria-hidden=\"true\"><textarea class=\"code-block-pro-copy-button-textarea\" tabindex=\"-1\" aria-hidden=\"true\" readonly>    static FILE* PopenEx(std::string command, PID_T* pidOut = nullptr);\n    static int Kill(PID_T pid);<\/textarea><\/pre><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M4.5 12.75l6 6 9-13.5\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6\"><\/path><\/svg><\/span><pre class=\"shiki dracula-soft\" style=\"background-color: #282A36\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">static<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #97E1F1; font-style: italic\">FILE<\/span><span style=\"color: #F286C4\">*<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">PopenEx<\/span><span style=\"color: #F6F6F4\">(std<\/span><span style=\"color: #F286C4\">::<\/span><span style=\"color: #97E1F1; font-style: italic\">string<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">command<\/span><span style=\"color: #F6F6F4\">, <\/span><span style=\"color: #97E1F1; font-style: italic\">PID_T<\/span><span style=\"color: #F286C4\">*<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">pidOut<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">=<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #BF9EEE\">nullptr<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F6F6F4\">    <\/span><span style=\"color: #F286C4\">static<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #F286C4\">int<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #62E884\">Kill<\/span><span style=\"color: #F6F6F4\">(<\/span><span style=\"color: #97E1F1; font-style: italic\">PID_T<\/span><span style=\"color: #F6F6F4\"> <\/span><span style=\"color: #FFB86C; font-style: italic\">pid<\/span><span style=\"color: #F6F6F4\">);<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p>\u800c\u540e\u5728\u505c\u6b62\u6293\u5305\u7684\u65f6\u5019\uff0c\u63d0\u524d\u6740\u6b7btshark\u8fdb\u7a0b\u5373\u53ef\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>05 \u83b7\u53d6\u5730\u7406\u4fe1\u606f \u2014\u2014\u975e\u590d\u5415\u8499\u4e4b\u4e09\u65e5\uff0c\u4f46\u89c1\u695a\u5e84\u4e4b\u98de\u9e23\u3002 wireshark\u4e2d\u662f\u6ca1\u6709\u83b7\u53d6\u5730\u7406\u4fe1\u606f\u529f\u80fd\u7684\uff0c\u8fd9\u7b97\u662f [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":93,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,7,8,9,3],"tags":[40,71,70,49],"class_list":["post-383","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c-c","category-network","category-network_codeing","category-network_knowledge","category-coding_language","tag-c","tag-tshark","tag-wireshark","tag-49"],"_links":{"self":[{"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/posts\/383"}],"collection":[{"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/comments?post=383"}],"version-history":[{"count":4,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/posts\/383\/revisions"}],"predecessor-version":[{"id":415,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/posts\/383\/revisions\/415"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/media\/93"}],"wp:attachment":[{"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/media?parent=383"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/categories?post=383"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/yangnanbei.top\/index.php\/wp-json\/wp\/v2\/tags?post=383"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}