轉: Android開發的網路抓包

來源:互聯網
上載者:User

標籤:

 

方法就是在android機器上面安裝tcpdump,然後通過-w參數把抓包記錄到本地,再把抓到的.cap檔案導到pc上面用wireshark來分析。這裡步驟非常多,在和後台聯調的時候,這個效率是非常低的。

能不能在android上面啟動抓包,然後直接在pc端看到即時抓包結果?

有了adb調試橋,我們就可以做到這麼便捷。

一、準備工具:

1、android 系統root2、android上安裝tcpdump3、android上安裝netcat,可以直接使用busybox的版本4、pc的wireshark的安裝目錄下需要有nc用戶端5、把android手機和pc通過usb調試串連上

二、命令:

1、android上先執行:

/data/tcpdump-arm -n -s 0 -w - | nc -l -p 11234

 * 11234是樣本,連接埠可以自己定

2、pc上啟動adb forward:

adb forward tcp:11234 tcp:11234 && nc64 127.0.0.1 11234 | wireshark -k -S -i -

 * 這裡的11234要和前面啟用11234要保持一致

3、如果抓包成功,那麼pc端的wireshark是自動啟動的,並且可以看到網路包

三、實現原理:

關鍵的邏輯在adb forward這個命令,這個命令實現了連接埠映射的功能:

Forwarding PortsYou can use the forward command to set up arbitrary port forwarding — forwarding of requests on a specific host port to a different port on an emulator/device instance. Here‘s how you would set up forwarding of host port 6100 to emulator/device port 7100:adb forward tcp:6100 tcp:7100You can also use adb to set up forwarding to named abstract UNIX domain sockets, as illustrated here:adb forward tcp:6100 local:logd 

轉: Android開發的網路抓包

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.