{"id":1267,"date":"2024-02-03T16:10:01","date_gmt":"2024-02-03T08:10:01","guid":{"rendered":"https:\/\/blog.purewind.top\/?p=1267"},"modified":"2024-11-27T13:40:17","modified_gmt":"2024-11-27T05:40:17","slug":"getipfromqq","status":"publish","type":"post","link":"https:\/\/foreverhome.live\/index.php\/2024\/02\/03\/getipfromqq\/","title":{"rendered":"\u3010C#\u3011\u6d45\u6790\u901a\u8fc7QQ\u7535\u8bdd\u83b7\u53d6\u76ee\u6807IP\u5730\u5740"},"content":{"rendered":"\n<p class=\"has-light-green-cyan-color has-text-color wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">\u4f7f\u7528\u7684\u8f6f\u4ef6\uff1a<\/mark><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>VisualStudio<\/li>\n<\/ul>\n\n\n\n<p class=\"has-light-green-cyan-color has-text-color wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00<\/mark><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>C#<\/li>\n<\/ul>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u6587\u4e2d\u6240\u6d89\u53ca\u7684\u6280\u672f\u3001\u601d\u8def\u548c\u5de5\u5177\u4ec5\u4f9b\u4ee5\u5b89\u5168\u4e3a\u76ee\u7684\u7684\u5b66\u4e60\u4ea4\u6d41\u4f7f\u7528<\/mark><\/strong><\/p>\n\n\n\n<p class=\"has-text-align-center wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u4efb\u4f55\u4eba\u4e0d\u5f97\u5c06\u5176\u7528\u4e8e\u975e\u6cd5\u7528\u9014\u4ee5\u53ca\u76c8\u5229\u7b49\u76ee\u7684\uff0c\u5426\u5219\u540e\u679c\u81ea\u884c\u627f\u62c5\uff01<\/mark><\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-center has-light-green-cyan-color has-text-color has-medium-font-size\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">\u524d\u8a00<\/mark><\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5176\u5b9e\u5f88\u65e9\u4e4b\u524d\u5e94\u8be5\u5c31\u6709\u5f88\u591a\u4eba\u51fa\u8fc7\u8bf8\u5982<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">\u201cQQ\u83b7\u53d6\u5bf9\u65b9IP\u201d<\/mark><\/strong>\u7b49\u7b49\u7684\u6587\u7ae0\uff0c\u5229\u7528<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Wireshark\u6293\u5305<\/mark><\/strong>\u5b9e\u73b0\u7b49\u7b49\u3002\u5728\u5f88\u4e45\u4e4b\u524d\u5df2\u7ecf\u5c1d\u8bd5\u8fc7\u662f\u4e2a\u53ef\u884c\u7684\u529e\u6cd5\uff0c\u6211\u731c\u6d4bQQ\u7535\u8bdd\u4e5f\u662f\u4f7f\u7528\u7c7b\u4f3c\u6253\u6d1e\u7684\u65b9\u5f0f\u8fdb\u884c\u6570\u636e\u4f20\u8f93\uff0c<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">\u7c7b\u4f3c\u7684\u8f6f\u4ef6\u8fd8\u6709TG\u7535\u62a5\u3001WX\u7b49\u7b49<\/mark><\/strong>\uff0c\u4f7f\u7528\u540c\u6837\u65b9\u5f0f\u7684\u8f6f\u4ef6\u5747\u53ef\u4ee5\u4f7f\u7528\u4e0a\u8ff0\u65b9\u5f0f\u6293\u5305\u83b7\u5f97\u5bf9\u65b9\u7684IP\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">\u4e0d\u4f1a\u8fc7\u591a\u8d58\u8ff0Wireshark\u5982\u4f55\u5b9e\u73b0\u83b7\u53d6IP\u8fd9\u4e00\u8fc7\u7a0b<\/mark><\/strong>\uff0c\u7f51\u4e0a\u6709\u592a\u591a\u6587\u7ae0\u505a\u8fc7\u89e3\u91ca\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ea\u501f\u6b21\u4e3a\u9898\uff0c<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">\u91cd\u70b9\u5c1d\u8bd5\u4f7f\u7528C#\u8c03\u7528SharpPcap\u5b9e\u73b0\u6293\u5305\u548c\u5904\u7406\uff0c\u83b7\u53d6\u5bf9\u65b9\u7684IP\u5730\u5740\uff0c\u5e76\u7b80\u5355\u4ecb\u7ecd\u4e00\u4e0bQQ\u7535\u8bdd\u4f7f\u7528UDP\u534f\u8bae\u53d1\u9001\u7684\u6570\u636e\u5305\u7ed3\u6784\uff0c\u4ee5\u91cd\u65b0\u590d\u4e60C#\u548cSharpPcap\u7684\u4f7f\u7528\u65b9\u5f0f\uff0c\u4ee5\u53ca\u5bf9wireshark\u6570\u636e\u5305\u8fdb\u884c\u6d45\u6790\u3002<\/mark><\/strong><\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-13409b240d0347a93d84fdf7016e34d2 wp-block-paragraph\"><strong>github\uff1a<a href=\"https:\/\/github.com\/Mangofang\/GetIPFromQQ\" target=\"_blank\"  rel=\"nofollow\" >https:\/\/github.com\/Mangofang\/GetIPFromQQ<\/a><\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-text-color has-cyan-bluish-gray-color has-alpha-channel-opacity has-cyan-bluish-gray-background-color has-background is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-left\" style=\"font-size:28px\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">1.\u4f7f\u7528Wireshark\u6293\u5305\u6d45\u6790\u6570\u636e\u5305\u7ed3\u6784<\/mark><\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6253\u5f00wireshark\u76d1\u542c\u76ee\u6807\u7f51\u5361\uff0c\u5e76\u5411\u76ee\u6807\u53d1\u51fa\u7535\u8bdd\u8bf7\u6c42\uff0c\u53ef\u4ee5\u770b\u5230\u6355\u83b7\u7684\u957f\u5ea6\u4e3a<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">114byte\u7684UDP\u534f\u8bae\u6570\u636e\u5305\uff08Source\u4e3a\u672c\u673a\u5730\u5740\uff0cDestination\u4e3a\u76ee\u6807\u5730\u5740\uff09<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9700\u8981\u6ce8\u610f\uff0c<strong>\u5bf9\u65b9\u53ef\u4ee5\u4e0d\u63a5\u901a\u672c\u6b21\u7535\u8bdd\uff0c\u4f46\u9700\u8981\u76ee\u6807\u5728\u7ebf\uff0c\u4e5f\u5c31\u662f\u9700\u8981\u5bf9\u65b9\u80fd\u591f\u54cd\u94c3<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2024\/02\/1706942343-QQ\u622a\u56fe20240203143728-1024x352.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/352;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u70b9\u51fb\u5355\u4e2a\u6570\u636e\u5305\uff0c\u5927\u81f4\u53ef\u4ee5\u5206\u4e3a\u4ee5\u4e0b\u56db\u4e2a\u90e8\u5206\uff0c\u5171\u540c\u6784\u6210\u4e86114byte\u7684\u6570\u636e\u5305<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">\u4ee5\u592a\u5e27\uff1a14byte<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">IPV4\u534f\u8bae\u5305\uff1a20byte<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">UDP\u534f\u8bae\u5305\uff1a8byte + UDP\u6570\u636e\u5305 72byte<\/mark><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2024\/02\/1706943530-QQ\u622a\u56fe20240203145828-1024x456.png\" alt=\"\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/456;width:840px;height:auto\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-medium-font-size\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">\u4ee5\u592a\u5e27<\/mark><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u7b80\u5355\u89e3\u91ca\u4e00\u4e0b<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">\u4ee5\u592a\u5e27<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4ee5\u592a\u7f51\u4e0a\u7684\u5176\u4ed6\u7f51\u7edc\u9002\u914d\u5668\u9700\u8981\u63a5\u6536\u5230\u4ee5\u592a\u5e27\uff0c\u68c0\u67e5\u5176\u4e2d\u7684\u76ee\u7684\u5730\u5740\u3002\u5982\u679c\u76ee\u7684\u5730\u5740\u4e0e\u7f51\u7edc\u9002\u914d\u5668\u7684\u5730\u5740\u76f8\u5339\u914d\uff0c\u9002\u914d\u5668\u8f6f\u4ef6\u5c31\u4f1a\u5904\u7406\u63a5\u6536\u5230\u7684\u5e27\uff0c\u628a\u6570\u636e\u4f20\u9012\u7ed9\u534f\u8bae\u6808\u4e2d\u8f83\u9ad8\u7684\u5c42\u3002<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u7ed3\u6784\u5982\u4e0b<\/strong><\/p>\n\n\n\n<p class=\"has-luminous-vivid-orange-color has-text-color has-link-color wp-elements-29f4536d9c41ca9f72f59b8d60f0bf35 wp-block-paragraph\"><a href=\"https:\/\/zhuanlan.zhihu.com\/p\/513345034\" target=\"_blank\"  rel=\"nofollow\" ><strong>\u4ee5\u592a\u5e27\u8d77\u59cb\u90e8\u5206\u7531\u524d\u5bfc\u7801\u548c\u5e27\u5f00\u59cb\u7b26\u7ec4\u6210\u3002\u540e\u9762\u7d27\u8ddf\u7740\u4e00\u4e2a\u4ee5\u592a\u7f51\u62a5\u5934\uff0c\u4ee5MAC\u5730\u5740\u8bf4\u660e\u76ee\u7684\u5730\u5740\u548c\u6e90\u5730\u5740\u3002\u5e27\u7684\u4e2d\u90e8\u662f\u8be5\u5e27\u8d1f\u8f7d\u7684\u5305\u542b\u5176\u4ed6\u534f\u8bae\u62a5\u5934\u7684\u6570\u636e\u5305(\u4f8b\u5982IP\u534f\u8bae)\u3002\u4ee5\u592a\u5e27\u7531\u4e00\u4e2a32\u4f4d\u5197\u4f59\u6821\u9a8c\u7801\u7ed3\u5c3e\u3002\u5b83\u7528\u4e8e\u68c0\u9a8c\u6570\u636e\u4f20\u8f93\u662f\u5426\u51fa\u73b0\u635f\u574f\u3002\uff08\u8f6c\u81f3\u77e5\u4e4e\uff09<\/strong><\/a><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2024\/02\/1706943745-QQ\u622a\u56fe20240203150205.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 841px; --smush-placeholder-aspect-ratio: 841\/203;\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading has-medium-font-size\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">IPV4\u534f\u8bae\u5305<\/mark><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">IPV4\u534f\u8bae\u5305\u4e2d\u542b\u6709\u6e90IP\u5730\u5740\u548c\u76ee\u6807IP\u5730\u5740<\/mark><\/strong>\uff0c\u6211\u4eec\u4e00\u4f1a\u513f\u5c31\u9700\u8981\u7528\u5230SharpPcap\u4eceIPV4\u534f\u8bae\u5305\u4e2d\u83b7\u53d6<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">Destination Address<\/mark><\/strong>\u4e2d\u7684\u76ee\u6807IP\u5730\u5740\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2024\/02\/1706944325-QQ\u622a\u56fe20240203151158.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 838px; --smush-placeholder-aspect-ratio: 838\/289;\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ed3\u6784\u5185\u5bb9\u5927\u81f4\u5982\u4e0b<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Version: 4 \/\/IP\u534f\u8bae\u7248\u672c:4\nHeader Length: 20 bytes \/\/\u5934\u90e8\u957f\u5ea6:20byte\nDifferentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT) \/\/\u670d\u52a1\u7c7b\u578b:0x00\nTotal Length: 100 \/\/\u603b\u957f\u5ea6:100byte\nIdentification: 0x5884 (22660) \/\/\u6807\u8bc6\u7b26:0x5884\nFlags: 0x00 \/\/\u6807\u5fd7:0x00\nTime to live: 128 \/\/\u5b58\u6d3b\u65f6\u95f4:1218\nProtocol: UDP(17) \/\/\u534f\u8bae\u7c7b\u578b:UDP \u53ef\u4ee5\u6ce8\u610f\u4ee5\u4e0b\uff0cUDP\u534f\u8bae\u5b57\u6bb5\u4e3a17\u3001TCP\u4e3a6\uff0c\u8fd8\u6709\u8bf8\u5982ICMP\u4e3a1\u7b49\n\nSource: 192.168.2.4 \/\/\u6e90IP\u5730\u5740\nDestination: 223.***.***.*** \/\/\u76ee\u6807IP\u5730\u5740<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading has-medium-font-size\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">UDP\u534f\u8bae\u6570\u636e\u5305<\/mark><\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u662f<strong>UDP\u534f\u8bae\u6570\u636e\u5305<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2024\/02\/1706944677-QQ\u622a\u56fe20240203151750.png\" alt=\"\" style=\"--smush-placeholder-width: 821px; --smush-placeholder-aspect-ratio: 821\/251;width:840px;height:auto\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">UDP\u6570\u636e\u5305\u7ed3\u6784\u5206\u4e3a<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">\u4e24\u4e2a\u4e3b\u8981\u90e8\u5206\uff1a\u4f2a\u9996\u90e8\u3001\u6570\u636e<\/mark><\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2024\/02\/1706944748-QQ\u622a\u56fe20240203144217.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 698px; --smush-placeholder-aspect-ratio: 698\/524;\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">\u9700\u8981\u6ce8\u610f\u4e00\u4e0b\uff0c<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">\u76ee\u6807IP\u5730\u5740\u53ea\u5b58\u5728\u4e8eIP\u534f\u8bae\u5305\u4e2d\uff0c\u4e5f\u5c31\u662f\u5728\u7f51\u7edc\u5c42\u4e2d\u83b7\u53d6\uff0c\u4e8c\u4e0d\u662f\u5728UDP\u3001TCP\u7b49\u4f20\u8f93\u5c42\u4e2d\u3002<\/mark><\/strong><\/p>\n\n\n\n<h2 class=\"wp-block-heading has-text-align-left\" style=\"font-size:28px\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-green-cyan-color\">2.\u4ee3\u7801\u90e8\u5206<\/mark><\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5148\u5728<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">NuGet\u4e2d\u5b89\u88c5SharpPcap<\/mark><\/strong>\uff0c\u7136\u540e<strong>\u5f15\u5165\u547d\u540d\u7a7a\u95f4<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using SharpPcap;\nusing SharpPcap.LibPcap;\nusing PacketDotNet;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u83b7\u53d6\u672c\u673a\u7f51\u5361\uff0c\u9009\u62e9\u6b63\u786e\u7684\u7f51\u5361\u542f\u52a8\u76d1\u542c<\/strong>\uff0c\u6211\u5f53\u524d\u7684\u7f51\u5361\u662fWLAN\uff0c\u4e5f\u5c31\u662f\u7f16\u53f7\u4e3a4\u7684\u7f51\u5361\u3002\u6240\u4ee5\u53ea\u8981\u83b7\u53d6devices[4]\uff0c\u6b64\u5904\u8c03\u8bd5\u8f93\u51fa\u4e00\u4e0b\u5373\u53ef<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2024\/02\/1706945267-QQ\u622a\u56fe20240203152619.png\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 629px; --smush-placeholder-aspect-ratio: 629\/447;\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>var devices = LibPcapLiveDeviceList.Instance;\nvar device = devices&#91;4];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u8bbe\u7f6e\u7f51\u5361\u8fc7\u6ee4\u6a21\u5f0f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>string filter = \"udp\";\ndevice.Filter = filter;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u6b64\u5904filter\u4f7f\u7528\u7684\u662f<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">libpcap\u8fc7\u6ee4\u5668\u8bed\u6cd5<\/mark><\/strong>\uff0c\u53ea\u83b7\u53d6UDP\u534f\u8bae\u7684\u6570\u636e\u5305\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u89c9\u5f97\u8fd9\u91cc\u53ef\u4ee5\u8be6\u7ec6\u5c55\u5f00\u6765\u8bf4\u4e00\u8bf4<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>libpcap\u8fc7\u6ee4\u5668\u8bed\u6cd5\uff1a\n\u9996\u5148\u4f60\u53ef\u4ee5\u4f7f\u7528\u534f\u8bae\u5173\u952e\u5b57\u6765\u786e\u5b9a\u8fc7\u6ee4\u7684\u534f\u8bae\n\u5982\uff1a\n  1.\"tcp\"\uff1a\u5339\u914dTCP\u534f\u8bae\u7684\u6570\u636e\u5305\u3002\n  2.\"udp\"\uff1a\u5339\u914dUDP\u534f\u8bae\u7684\u6570\u636e\u5305\u3002\n  3.\"icmp\"\uff1a\u5339\u914dICMP\u534f\u8bae\u7684\u6570\u636e\u5305\u3002\n\u5176\u6b21\u5982\u4f55\u8fc7\u6ee4\u6e90IP\u548c\u76ee\u6807IP\u5462\uff1f\n\u4f7f\u7528host\u5173\u952e\u5b57\u6765\u83b7\u53d6IP\uff0c\u540c\u65f6\u4f7f\u7528src\u548cdst\u6765\u8868\u793a\u6e90\u548c\u76ee\u6807\u7684IP\n\u5982\uff1a\n  1.\"src host 192.168.0.1\"\uff1a\u5339\u914d\u6e90IP\u5730\u5740\u4e3a192.168.0.1\u7684\u6570\u636e\u5305\u3002\n  2.\"dst host 10.0.0.1\"\uff1a\u5339\u914d\u76ee\u6807IP\u5730\u5740\u4e3a10.0.0.1\u7684\u6570\u636e\u5305\u3002\n\u90a3\u4e48\u7aef\u53e3\u5462\n\u6211\u4eec\u521a\u521a\u6709\u8bf4host\u5173\u952e\u5b57\u662fIP\uff0c\u90a3\u81ea\u7136port\u5173\u952e\u5b57\u5c31\u662f\u7aef\u53e3\u3002\u6240\u4ee5\u540c\u4e0a\n  1.\"src port 80\"\uff1a\u5339\u914d\u6e90\u7aef\u53e3\u53f7\u4e3a80\u7684\u6570\u636e\u5305\u3002\n  2.\"dst port 443\"\uff1a\u5339\u914d\u76ee\u6807\u7aef\u53e3\u53f7\u4e3a443\u7684\u6570\u636e\u5305\u3002\n\u903b\u8f91\u8fd0\u7b97\u7b26\n  1.\"and\"\uff1a\u7528\u4e8e\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u8868\u793a\u540c\u65f6\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\u3002\n  2.\"or\"\uff1a\u7528\u4e8e\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u8868\u793a\u6ee1\u8db3\u5176\u4e2d\u4efb\u610f\u4e00\u4e2a\u6761\u4ef6\u3002\n  3.\"not\"\uff1a\u7528\u4e8e\u5426\u5b9a\u4e00\u4e2a\u6761\u4ef6\uff0c\u8868\u793a\u4e0d\u6ee1\u8db3\u8be5\u6761\u4ef6\u3002\n\u4e3e\u4e2a\u4f8b\u5b50\n  1.\"tcp and port 80\"\uff1a\u5339\u914dTCP\u534f\u8bae\u4e14\u76ee\u6807\u6216\u6e90\u7aef\u53e3\u53f7\u4e3a80\u7684\u6570\u636e\u5305\u3002\n  2.\"udp and src host 192.168.0.1\"\uff1a\u5339\u914dUDP\u534f\u8bae\u4e14\u6e90IP\u5730\u5740\u4e3a192.168.0.1\u7684\u6570\u636e\u5305\u3002\n  3.\"icmp or dst host 10.0.0.1\"\uff1a\u5339\u914dICMP\u534f\u8bae\u6216\u76ee\u6807IP\u5730\u5740\u4e3a10.0.0.1\u7684\u6570\u636e\u5305\u3002<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">\u6ce8\u518c\u4e00\u4e2a\u59d4\u6258\u4e8b\u4ef6<\/mark><\/strong>\uff0c\u8ba9\u6293\u5230\u5305\u4e4b\u540e\u901a\u8fc7\u8fd9\u4e2a\u4e8b\u4ef6\u6765\u6267\u884c\u64cd\u4f5c<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>device.OnPacketArrival += new PacketArrivalEventHandler(PacketHandler);\ndevice.StartCapture();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5177\u4f53\u7684\u5185\u5bb9\u6211\u4eec\u5c31\u53ef\u4ee5\u5728<strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">PacketHandler\u51fd\u6570<\/mark><\/strong>\u4e2d\u5b8c\u6210<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u7684\u76ee\u7684\u662f\u83b7\u53d6\u76ee\u6807\u7684IP\u5373\u53ef\uff0c\u4e0a\u6587\u8bf4\u8fc7<strong>\u76ee\u6807IP\u5b58\u5728\u4e8eIPV4\u534f\u8bae\u5305\u4e2d<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>var ent = EthernetPacket.ParsePacket(LinkLayers.Ethernet, e.Packet.Data);\/\/\u83b7\u53d6\u4ee5\u592a\u5e27\nvar ip = ent.PayloadPacket;\/\/\u83b7\u53d6IP\u534f\u8bae\u5305\nvar udp = ip.PayloadPacket;\/\/\u83b7\u53d6UDP\u534f\u8bae\u5305\nvar data_len = udp.PayloadData.Length;\/\/\u8bfb\u53d6UDP\u6570\u636e\u5305Data\u7684\u957f\u5ea6<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u8fc7\u6b63\u5219\u8fc7\u6ee4\u83b7\u5f97\u76ee\u6807IP<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Match match = Regex.Match(ip.ToString(), @\"DestinationAddress=(\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3})\");\nstring DestinationAddress = match.Groups&#91;1].Value;\nConsole.WriteLine(\"\u5df2\u6355\u83b7\u76ee\u6807IP\uff1a\" + DestinationAddress);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u540e\u62ff\u5230IP\u8fd8\u4e0d\u884c\uff0c\u56e0\u4e3a\u6211\u4eec\u6b64\u65f6\u53ea\u662f\u83b7\u53d6\u4e86\u6240\u6709UDP\u6570\u636e\u5305\u4e2d\u7684\u76ee\u6807IP\u5730\u5740\uff0c\u600e\u4e48\u5224\u65ad\u662f\u4e0d\u662fQQ\u7535\u8bdd\u7684\u6570\u636e\u5305\u5462\uff1f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u53ef\u4ee5\u901a\u8fc7\u5224\u65adIPV4\u6570\u636e\u5305\u957f\u5ea6\uff1a100<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-luminous-vivid-orange-color\">\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5224\u65adUDP\u534f\u8bae\u6570\u636e\u5305\u957f\u5ea6\uff1a72<\/mark><\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u901a\u5e38QQ\u7535\u8bdd\u4e2d\u7684UDP\u6570\u636e\u5305\u957f\u5ea6\u662f\u56fa\u5b9a\u7684\uff0c<strong>\u6240\u4ee5\u5224\u65adUDP\u534f\u8bae\u6570\u636e\u5305\u957f\u5ea6\u53ef\u4fe1\u5ea6\u4f1a\u66f4\u9ad8\u4e00\u4e9b<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (data_len == 72 &amp;&amp; !DestinationAddress.Contains(\"192.168\"))\n{\n    Console.WriteLine(\"\u5df2\u6355\u83b7\u76ee\u6807IP\uff1a\" + DestinationAddress);\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u7ec8\u5b8c\u6210\u83b7\u53d6<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/foreverhome.live\/wp-content\/uploads\/2024\/02\/1706946857-2024-02-03-03-41-48_1-2.gif\" alt=\"\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 1440px; --smush-placeholder-aspect-ratio: 1440\/810;\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u7684\u8f6f\u4ef6\uff1a \u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00 \u6587\u4e2d\u6240\u6d89\u53ca\u7684\u6280\u672f\u3001\u601d\u8def\u548c\u5de5\u5177\u4ec5\u4f9b\u4ee5\u5b89\u5168\u4e3a\u76ee\u7684\u7684\u5b66\u4e60\u4ea4\u6d41\u4f7f\u7528 \u4efb\u4f55\u4eba\u4e0d\u5f97\u5c06\u5176\u7528\u4e8e\u975e\u6cd5\u7528\u9014\u4ee5\u53ca\u76c8\u5229\u7b49\u76ee\u7684 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[6],"tags":[],"class_list":["post-1267","post","type-post","status-publish","format-standard","hentry","category-networksecurity"],"_links":{"self":[{"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/posts\/1267","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/comments?post=1267"}],"version-history":[{"count":13,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/posts\/1267\/revisions"}],"predecessor-version":[{"id":1691,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/posts\/1267\/revisions\/1691"}],"wp:attachment":[{"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/media?parent=1267"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/categories?post=1267"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/foreverhome.live\/index.php\/wp-json\/wp\/v2\/tags?post=1267"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}