在mac下面,竟然沒有好的抓包工具,這讓我十分糾結,畢竟不可能爲了抓一個http包就跑到win下折騰。或許有人說tcpdump這麼好的工具,你怎麼不用。說實話,tcpdump太複雜了,我尚未細看,再加上不是所見所得,因此,用起來不是那麼習慣chrome
又有人說,wireshark怎麼不用?好吧,其實我是有裝wireshark,只是啓動的時候會啓動XQuartz,有點慢,固然這不是主要的,而是wireshark功能太強大了,以致於都不會寫過濾器。windows
也有人說,圖方便的話,徹底能夠用chrome自帶的抓包工具啊?在沒有找到這個工具以前,你能夠嘗試在地址欄輸 入:chrome://chrome-urls/,你會發現chrome原來有這麼多的隱藏工具,嗯。我要說的就是其中的一個:chrome: //net-internals/ ,在Events中,你能夠進行過濾,不過,針對https的包,內容無法顯示api
愈來愈懷念windows下面,smartsniff徹底就是wireshark的簡化版,抓起包來刷刷的,過濾數據也很方便。瀏覽器
固然,mac下面的charles就真心不錯了,試用了一下,果真對於https的包也可以抓取。服務器
這裏有一個簡單的教程(實際操做略有出入):網絡
在Mac下作開發,用Fiddler抓包因爲離不開Windows比較痛苦,還好有Charles,到官網http://www.charlesproxy.com/可下載到最新版本(若不支持rMBP可拖到Retinizer中把文字變清晰)app
打開Charles程序tcp
查看Mac電腦的IP地址,如192.168.1.7工具
打開iOS設置,進入當前wifi鏈接,設置HTTP代理Group,將服務器填爲上一步中得到的IP,即192.168.1.7,端口填8888ui
iOS設備打開你要抓包的app進行網絡操做
Charles彈出確認框,點擊Allow按鈕便可
下載Charles證書http://www.charlesproxy.com/ssl.zip,解壓後導入到iOS設備中(將crt文件做爲郵件附件發給本身,再在iOS設備中點擊附件便可安裝;也可上傳至dropbox之類的網盤,經過safari下載安裝)
在Charles的工具欄上點擊設置按鈕,選擇Proxy Settings…
切換到SSL選項卡,選中Enable SSL Proxying,別急,選完先別關掉,還有下一步
這 一步跟Fiddler不一樣,Fiddler安裝證書後就能夠抓HTTPS網址的包了,Charles則麻煩一些,須要在上一步的SSL選項卡的 Locations表單填寫要抓包的域名和端口,點擊Add按鈕,在彈出的表單中Host填寫域名,好比填api.instagram.com,Port 填443
接下來就跟HTTP抓包同樣了
---EOF---
上文中的一些操做,實際上是有點出入的(HTTPS)抓包
一、若是沒有設置ssl的話,那麼你看到的ssl的接口中,會有一個報錯:SSL Proxying not enabled for this host: enable in Proxy Settings, SSL locations,這個時候,在左側的域名上點右鍵:enable ssl,就OK了。(其實就是上面的第4部,不過這個操做是簡化操做,上面的第4步太麻煩了)
二、若是這樣仍是不能抓包,那麼官方會有一個說明(http://www.charlesproxy.com/documentation/using-charles/ssl-certificates/):
Download and unzip the Charles CA Certificate bundle. The bundle contains the Charles CA Certificate file.
Run the Keychain Access utility from the Applications/Utilities folder. This tool enables you to manage your certificates.
Choose the "login" keychain then go to the File menu and choose Import. Choose the .crt file you downloaded above, and ensure that the login keychain is chosen in the dropdown menu.
Complete the import and the Charles CA SSL Certificate will now be trusted for your login account.
Move the Charles Proxy SSL Proxying certificate from your login keychain to the System keychain by drag-and-drop if you want all users on the machine to trust it.
You will need to quit and reopen Safari to see the change.
On Mac OS X, please follow the instructions for Mac OS X above. These instructions only apply on Windows.
Open the Options dialog, go to the "Under the Hood" tab, then click the "Manage certificates" button.
Go to the Trusted Root Certification Authorities tab and click Import.
Find the charles-proxy-ssl-proxying-certificate.crt file. On Windows and Linux it is in the docs directory in your Charles installation directory. On Mac OS X (or if you can’t find it) you can download and unzip ssl.zip.
Choose the charles-proxy-ssl-proxying-certificate.crt file, then click Next and Finish, leaving the default options, until you complete the import. Chrome will now always trust certificates signed by Charles.
After importing you can delete the charles-proxy-ssl-proxying-certificate.crt file if you downloaded it.
---若是用chrome,那就直接可使用/若是firefox,會有插件提示你安裝/若是是safari,則須要打開證書管理器,將剛纔導入的 證書把login改成system(這樣全部用戶就都能使用了,不過都是本身的電腦,無所謂了),safari可能須要重啓下瀏覽器
經此,我終於能夠抓包了。並且https包也再也不只是一堆 亂碼。黑黑