使用httpreques\Json-Handle\tcpdump\wireshark工具進行,抓取手機訪問網絡的包,分析request及response請求,通過httprequester來實現模擬發包及接收.
對於手機開發,分析手機訪問網絡數據,十分必要!
1.使用tcpdump包抓取網絡數據包,手機要root,抓取過程請看:
1. 手機要有root權限
2. 下載tcpdump http://www.strazzere.com/android/tcpdump
3. adb push c:\wherever_you_put\tcpdump /data/local/tcpdump
4. adb shell chmod 6755 /data/local/tcpdump
5, adb shell, su獲得root權限
6, cd /data/local
7, ./tcpdump -i any -p -s 0 -w /sdcard/capture.pcap
命令參數:
# "-i any": listen on any network interface
# "-p": disable promiscuous mode (doesn't work anyway)
# "-s 0": capture the entire packet
# "-w": write packets to a file (rather than printing to stdout)
... do whatever you want to capture, then ^C to stop it ...
8, adb pull /sdcard/capture.pcap d:/
9, 在電腦上用wireshark打開capture.pcap即可分析log
Execute the following if you would like to watch packets go by rather than capturing them to a file (-n skips DNS lookups. -s 0 captures the entire packet rather than just the header):
adb shell tcpdump -n -s 0
Typical tcpdump options apply. For example, if you want to see HTTP traffic:
只監聽http
adb shell tcpdump -X -n -s 0 port 80
根據以上的信息,寫一個bat去執行(tcpdump文件必須在當前目錄里)。
開始tcpdump
adb push tcpdump /data/local/tcpdump
adb shell chmod 6755 /data/local/tcpdump
adb shell rm -r /sdcard/capture.pcap
adb shell /data/local/tcpdump -i any -p -s 0 -w /sdcard/capture.pcap
pause
下載tcpdump文件到電腦
adb pull /sdcard/capture.pcap capture.pcap
問題:有些機器root后通過adb shell 后,默認不是root用戶,需要輸入 su才能切換到root,這樣在執行批處理會有問題,解決方法如下
adb shell "su -c 'sleep 1'"
adb start-server
adb push tcpdump /data/local/tcpdump
2.通過wireshark工具打開剛才抓取的數據包,可通過http&&ip.addr==119.161.212.35(手機網絡訪問的目標IP地址)這樣的語句過濾,准確得到有用的數據

3.定位到具體的某一個包,雙擊打開后找出請求的http地址,以及Json數據,本例中的數據為,些請求是更用戶所設置的學校及院系信息,地址可用,可試着修下Json中的內容.
http://kechengbiao.me/popular.json
{"from_app":true,"department_name":"EECS","school_name":"北京大學","token":"EHFWUCVRRSKATAOHAGTBSR","user":{"grade":2011,"sex":1,"name":"mingyong"},"locale":"ch"}
4.打開Firefox使用其插件HttpRequester及Json-handle來模擬手機提交post請求,並查年返回數據
將上面得到的http地址及json輸入到httprequest中,如圖:

5.第四步是在本例中實際更新學校的post請求,根據已知的http請求,查看是否更新成功:
http://kechengbiao.me/popular.json?token=EHFWUCVRRSKATAOHAGTBSR&locale=ch&from_app=true&version=1.51
如圖:

由於Firefox安裝了Json-handle,打開網頁后默認解析Json數據.
