{"id":1377,"date":"2024-03-16T01:52:27","date_gmt":"2024-03-15T17:52:27","guid":{"rendered":"http:\/\/www.ccwifi.cc\/blogs\/?p=1377"},"modified":"2024-03-16T01:52:27","modified_gmt":"2024-03-15T17:52:27","slug":"ubuntu%e4%b8%8b%e9%80%9a%e8%bf%87wireshark%e6%8a%93%e5%8f%96wifi%e6%95%b0%e6%8d%ae%e5%8c%85","status":"publish","type":"post","link":"https:\/\/www.ccwifi.cc\/blogs\/2024\/03\/16\/ubuntu%e4%b8%8b%e9%80%9a%e8%bf%87wireshark%e6%8a%93%e5%8f%96wifi%e6%95%b0%e6%8d%ae%e5%8c%85\/","title":{"rendered":"ubuntu \u4e0b\u901a\u8fc7 wireshark \u6293\u53d6 wifi \u6570\u636e\u5305"},"content":{"rendered":"<div>\n<p>\u5728\u7ebfwifi\u8dd1\u5305 \u91d1\u521a\u5305\u8dd1\u5305 cap\u8dd1\u5305 hccapx ewsa\u5728\u7ebf \u5c31\u6765 <strong><a href=\"https:\/\/ccwifi.cc\" target=\"_blank\" rel=\"noopener\">\u63e1\u624b\u5305\u8dd1\u5305<\/a><\/strong><\/p>\n<p>\u5404\u4f4d\u597d \u53c8\u89c1\u9762\u4e86 \u6211\u662f\u66f9\u64cd \u4eca\u5929\u7ed9\u5927\u5bb6\u5e26\u6765\u4e00\u7bc7\u65b0\u7684\u6559\u7a0b<\/p>\n<p>\u5e0c\u671b\u5404\u4f4d\u7ec6\u5fc3\u5b66\u4e60 \u4f4e\u8c03\u7528\u7f51<\/p>\n<\/div>\n<p><img decoding=\"async\" src=\"http:\/\/www.ccwifi.cc\/blogs\/wp-content\/uploads\/2024\/03\/1710525146581_3.png\" alt=\"\u63e1\u624b\u5305\u6293\u53d6\u8f6f\u4ef6\"><\/p>\n<h3 id=\"1cappiplibpcap\">\u56de\u7b541\uff1a\u4e3a\u4e86\u5728C\u8bed\u8a00\u4e2d\u6293\u53d6\u63a5\u5165\u6e38\u620f\u76fe\u7684APP\u7684\u771f\u5b9eIP\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528libpcap\u5e93\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u7684\u6b65\u9aa4\uff1a<\/h3>\n<ol>\n<li>\n<p>\u5b89\u88c5libpcap\u5e93\uff1a\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5b89\u88c5\uff0c\u4f8b\u5982\u5728Ubuntu\u4e2d\u53ef\u4ee5\u4f7f\u7528<code>sudo apt-get install libpcap-dev<\/code>\u547d\u4ee4\u5b89\u88c5\u3002\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u60a8\u9700\u8981\u4e0b\u8f7dlibpcap\u5e93\u7684Windows\u7248\u672c\u5e76\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/li>\n<li>\n<p>\u5728C\u7a0b\u5e8f\u4e2d\u5305\u542blibpcap\u5e93\u7684\u5934\u6587\u4ef6\uff1a<code>#include &lt;pcap.h&gt;<\/code><\/p>\n<\/li>\n<li>\n<p>\u8c03\u7528libpcap\u5e93\u7684\u51fd\u6570pcap<em>open<\/em>live()\u6253\u5f00\u7f51\u7edc\u63a5\u53e3\uff0c\u5e76\u4f7f\u7528pcap_loop()\u51fd\u6570\u5f00\u59cb\u6293\u5305\u3002<\/p>\n<\/li>\n<li>\n<p>\u5b9a\u4e49\u4e00\u4e2a\u56de\u8c03\u51fd\u6570\uff0c\u5728\u6bcf\u6b21\u6293\u5230\u6570\u636e\u5305\u65f6\u8c03\u7528\u3002\u5728\u56de\u8c03\u51fd\u6570\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528libpcap\u5e93\u63d0\u4f9b\u7684\u51fd\u6570\u89e3\u6790\u6570\u636e\u5305\uff0c\u5e76\u4ece\u4e2d\u83b7\u53d6\u771f\u5b9eIP\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u8be5\u4ee3\u7801\u4f7f\u7528libpcap\u5e93\u6293\u53d6\u7b2c\u4e00\u4e2a\u6570\u636e\u5305\u5e76\u6253\u5370\u51fa\u6765\uff1a<\/p>\n<pre><code class=\"c language-c\">#include &lt;stdio.h&gt;\n#include &lt;pcap.h&gt;\n\nvoid got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet){\n    printf(\"Got a packet!\\n\");\n}\n\nint main(int argc, char *argv[]){\n    pcap_t *handle;\n    char *dev;\n    char errbuf[PCAP_ERRBUF_SIZE];\n    struct bpf_program fp;\n    char filter_exp[] = \"port 80\";\n    bpf_u_int32 mask;\n    bpf_u_int32 net;\n\n    \/\/ Step 1: Find a device\n    dev = pcap_lookupdev(errbuf);\n    if (dev == NULL) {\n        fprintf(stderr, \"Couldn't find default device: %s\\n\", errbuf);\n        return 2;\n    }\n\n    \/\/ Step 2: Open device\n    handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf);\n    if (handle == NULL) {\n        fprintf(stderr, \"Couldn't open device %s: %s\\n\", dev, errbuf);\n        return 2;\n    }\n\n    \/\/ Step 3: Capture packets\n    pcap_loop(handle, 1, got_packet, NULL);\n\n    \/\/ Step 4: Close handle\n    pcap_close(handle);\n\n    return 0;\n}\n<\/code><\/pre>\n<h3 id=\"2cappipwireshark\">\u56de\u7b542\uff1a\u8981\u5728C\u8bed\u8a00\u4e2d\u6293\u53d6\u63a5\u5165\u6e38\u620f\u76fe\u7684APP\u7684\u771f\u5b9eIP\uff0c\u60a8\u9700\u8981\u4e86\u89e3Wireshark\u8f6f\u4ef6\u548c\u7f51\u7edc\u7f16\u7a0b\u77e5\u8bc6\u3002\u4ee5\u4e0b\u662f\u5b9e\u73b0\u7684\u57fa\u672c\u6b65\u9aa4\uff1a<\/h3>\n<ol>\n<li>\n<p>\u4f7f\u7528C\u8bed\u8a00\u7684socket\u51fd\u6570\u521b\u5efa\u4e00\u4e2a\u5957\u63a5\u5b57\uff0c\u5efa\u7acb\u4e0e\u7f51\u7edc\u7684\u8fde\u63a5\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528bind\u51fd\u6570\u5c06\u5957\u63a5\u5b57\u548c\u672c\u673a\u7684IP\u5730\u5740\u53ca\u7aef\u53e3\u53f7\u7ed1\u5b9a\u3002<\/p>\n<\/li>\n<li>\n<p>\u8c03\u7528recvfrom\u51fd\u6570\u63a5\u6536\u6765\u81ea\u7f51\u7edc\u7684\u6570\u636e\u5305\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528Wireshark\u7684\u6293\u5305\u529f\u80fd\uff0c\u67e5\u627e\u6e38\u620f\u76feAPP\u53d1\u9001\u548c\u63a5\u6536\u7684\u6570\u636e\u5305\uff0c\u83b7\u53d6\u6570\u636e\u5305\u7684\u6e90IP\u5730\u5740\u548c\u76ee\u6807IP\u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\u901a\u8fc7\u89e3\u6790\u6570\u636e\u5305\uff0c\u63d0\u53d6\u5e76\u8bb0\u5f55\u6e38\u620f\u76feAPP\u7684\u771f\u5b9eIP\u5730\u5740\u3002<\/p>\n<\/li>\n<li>\n<p>\u4f7f\u7528C\u8bed\u8a00\u7684\u7f51\u7edc\u7f16\u7a0b\u51fd\u6570\uff0c\u5c06\u8bb0\u5f55\u7684IP\u5730\u5740\u4f20\u8f93\u7ed9\u671f\u671b\u7684\u76ee\u6807\u670d\u52a1\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4e3a\u4e86\u6293\u53d6\u6e38\u620f\u76feAPP\u7684\u771f\u5b9eIP\u5730\u5740\uff0c\u6211\u4eec\u9700\u8981\u5728\u64cd\u4f5c\u7cfb\u7edf\u7684\u7f51\u7edc\u6808\u4e2d\u63d0\u5347\u7279\u6743\uff0c\u56e0\u4e3a\u6e38\u620f\u76feAPP\u901a\u5e38\u4f1a\u4f7f\u7528\u4e00\u4e9b\u6280\u5de7\u6765\u9690\u85cf\u771f\u5b9eIP\u5730\u5740\u3002<\/p>\n<p>\u4ee5\u4e0a\u662f\u7528C\u8bed\u8a00\u5b9e\u73b0Wireshark\u6293\u53d6\u63a5\u5165\u6e38\u620f\u76fe\u7684APP\u771f\u5b9eIP\u7684\u57fa\u672c\u6b65\u9aa4\u3002\u5177\u4f53\u5b9e\u73b0\u9700\u8981\u6839\u636e\u5177\u4f53\u60c5\u51b5\u548cWireshark\u7684\u4f7f\u7528\u8981\u6c42\u8fdb\u884c\u3002\u540c\u65f6\uff0c\u9700\u8981\u9075\u5b88\u6cd5\u5f8b\u6cd5\u89c4\u548c\u9053\u5fb7\u89c4\u8303\uff0c\u786e\u4fdd\u5408\u6cd5\u4f7f\u7528\u5e76\u4fdd\u62a4\u7528\u6237\u9690\u79c1\u3002<\/p>\n<p><!-- \u6587\u7ae0\u6765\u6e90:https:\/\/blog.csdn.net\/merry1996\/article\/details\/105858834 --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>ubuntu \u4e0b\u901a\u8fc7 wireshark \u6293\u53d6 wifi \u6570\u636e\u5305### \u56de\u7b541\uff1a\u60a8\u53ef\u4ee5\u4f7f\u7528 libpcap \u5e93\u6765\u5b9e\u73b0\u5728 C \u8bed\u8a00\u4e2d\u6293\u53d6\u63a5\u5165\u6e38\u620f\u76fe\u7684 APP \u7684\u771f\u5b9e IP\u3002\u5177\u4f53\u6765\u8bf4\uff0c\u60a8\u9700\u8981\uff1a1. \u5b89\u88c5 libpcap \u5e93\uff1a\u5728 Linux \u7cfb\u7edf\u4e2d<\/p>\n","protected":false},"author":1,"featured_media":1378,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"topic":[],"class_list":["post-1377","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-1"],"_links":{"self":[{"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/posts\/1377","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/comments?post=1377"}],"version-history":[{"count":0,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/posts\/1377\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/media\/1378"}],"wp:attachment":[{"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/media?parent=1377"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/categories?post=1377"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/tags?post=1377"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.ccwifi.cc\/blogs\/wp-json\/wp\/v2\/topic?post=1377"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}