自動(dòng)設(shè)置安卓手機(jī)wifi代理的PowerShell腳本
在實(shí)際測(cè)試工作中,經(jīng)常要將安卓手機(jī)通過wifi代理的形式連接到本機(jī)的fiddler或charles服務(wù)器代理進(jìn)行抓包測(cè)試。最近一直在想,有沒有什么方法可以自動(dòng)設(shè)置安卓手機(jī)的wifi代理,曾經(jīng)想通過修改安卓系統(tǒng)配置文件的方式來修改但是沒有找到解決方案。最后決定針對(duì)自己的手機(jī)進(jìn)行私人訂制,缺點(diǎn)是只能針對(duì)固定機(jī)型進(jìn)行設(shè)置,不過優(yōu)點(diǎn)是腳本很好編寫,可以很快的對(duì)自己平時(shí)使用的測(cè)試機(jī)進(jìn)行定制(非Windows下的腳本編寫過程類似)。
利用adb命令編寫PowerShell腳本
Windows下編寫腳本用到了PowerShell和adb相關(guān)命令,腳本內(nèi)容如下(坐標(biāo)定位用uiautomatorviewer就可以):
Write-Host "更改設(shè)置中……" -ForegroundColor Green
#點(diǎn)擊Home鍵返回Home頁并進(jìn)入網(wǎng)絡(luò)設(shè)置頁面
adb shell input keyevent 3
adb shell am start -a android.settings.WIRELESS_SETTINGS
adb shell input tap 421 570
adb shell input tap 421 570
adb shell input tap 605 1665
#手動(dòng)設(shè)置代理
#刪除主機(jī)名
adb shell input swipe 972 1687 972 1686 1500
#獲取本機(jī)ip
$ip = (ipconfig|findstr "IPv4"|findstr "10.234").split(":")[1]
#修改主機(jī)名為本機(jī)ip
adb shell input text $ip
#收起軟鍵盤
adb shell input tap 997 1250
#向上滑動(dòng)屏幕
adb shell input swipe 813 1626 794 201 1000
#點(diǎn)擊端口框
adb shell input tap 955 1461
#刪除端口號(hào)
adb shell input swipe 986 1388 986 1386 1000
#輸入端口號(hào)8888
adb shell input tap 547 1688
adb shell input tap 547 1688
adb shell input tap 547 1688
adb shell input tap 547 1688
#點(diǎn)擊返回按鈕
adb shell input tap 1009 1853
#下一項(xiàng)
adb shell input tap 1009 1853
#完成設(shè)置
adb shell input tap 1009 1853
#返回設(shè)置界面
adb shell input tap 77 126
#返回Home頁
adb shell input keyevent 3
Write-Host "手機(jī)wifi代理設(shè)置完畢,已與本機(jī)相連,請(qǐng)開抓包工具!" -ForegroundColor Green
Read-Host
將腳本編譯為exe可執(zhí)行文件
可以進(jìn)一步將PowerShell腳本轉(zhuǎn)化為可雙擊執(zhí)行的exe文件。推薦使用Ps1 To Exe Online Converter這款在線應(yīng)用上傳腳本進(jìn)行轉(zhuǎn)化后下載。點(diǎn)擊解壓后的exe文件,運(yùn)行效果如下:

以上就是自動(dòng)設(shè)置安卓手機(jī)wifi代理的PowerShell腳本的詳細(xì)內(nèi)容,更多關(guān)于自動(dòng)設(shè)置代理power shell腳本的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
PowerShell函數(shù)參數(shù)設(shè)置成自動(dòng)識(shí)別數(shù)據(jù)類型的例子
這篇文章主要介紹了PowerShell函數(shù)參數(shù)設(shè)置成自動(dòng)識(shí)別數(shù)據(jù)類型的例子,這個(gè)方法可以很方便的使用參數(shù)集,而不用每次指定名稱,需要的朋友可以參考下2014-07-07
Windows Powershell Foreach 循環(huán)
Foreach-object 為cmdlet命令,使用在管道中,對(duì)管道結(jié)果逐個(gè)處理,foreach為遍歷集合的關(guān)鍵字。2014-10-10
PowerShell獲取系統(tǒng)環(huán)境變量的方法
這篇文章主要介紹了PowerShell獲取系統(tǒng)環(huán)境變量的方法,本文講解了列出所有的環(huán)境變量的方法和獲取環(huán)境變量的值的方法,需要的朋友可以參考下2014-08-08
Windows Powershell Switch 循環(huán)
這篇文章主要介紹了Windows Powershell Switch 循環(huán)以及PowerShell中數(shù)組可以與switch語句結(jié)合,產(chǎn)生意想不到的效果。2014-10-10
PowerShell腳本清理指定天數(shù)前的臨時(shí)文件夾實(shí)現(xiàn)代碼
這篇文章主要介紹了PowerShell腳本清理指定天數(shù)前的臨時(shí)文件夾實(shí)現(xiàn)代碼,指定天數(shù)可以任意修改數(shù)字實(shí)現(xiàn),需要的朋友可以參考下2014-08-08
PowerShell中直接輸出轉(zhuǎn)義字符或變量名稱的方法
這篇文章主要介紹了PowerShell中直接輸出轉(zhuǎn)義字符或變量名稱的方法,也就是原樣輸出字符串,不理會(huì)字符串可能包含的換行符、變量等,需要的朋友可以參考下2014-08-08

