2017-02-17 77 views
0

對於一般的計算器和編碼是新的。我能夠編寫一個批處理文件來解析網絡中s​​onos播放器的一組IP地址,我還能夠編寫一個單獨的批處理文件,使用這些IP地址執行HTTP命令以關閉無線網絡在所有單元上,但我必須手動輸入第一批中的所有IP地址。我想知道是否有方法可以將IP地址自動輸入到第二個批處理文件中,或者如果有辦法,我可以編寫一個批處理文件,它將一次完成所有工作。下面的例子只涉及2個IP,現實世界我需要這個與20+以上的工作,所以這就是爲什麼我想找到一種方法來自動輸入的IPsCMD/Batch:如何在另一組命令中使用FOR/F循環的輸出

任何幫助,非常感謝!

第一批:GetIPlist.bat

FOR /F "tokens=3 delims= " %%a in ('findstr "IP Address: *[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" AboutMySonos.txt') DO echo %%a 

它返回的IP名單如下:

192.168.2.174 
192.168.2.24 

第二批:SonosWifiDefeat.bat

@echo off 

start "http://IpAddress:1400/wifictrl?wifi=persist-off" 
ping 1.1.1.1 -n 1 -w 1000 > nul 
start "http://IpAddress:1400/wifictrl?wifi=persist-off" 

回答

1

兩者結合起來!

FOR /F "tokens=3 delims= " %%a in ('findstr "IP Address: *[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*" AboutMySonos.txt') DO (
    start "http://%%a:1400/wifictrl?wifi=persist-off" 
    ping %%a -n 1 -w 1000 > nul 
    start "http://%%a:1400/wifictrl?wifi=persist-off" 
) 

,或者甚至更好,使用PowerShell所以你不必打開start百瀏覽器窗口的更多信息:

Select-String -path .\AboutMySonos.txt -pattern "IpAddress: (.*)" | ForEach { 
    ip=$_.Matches.Groups[1].Value 
    Invoke-RestMethod "http://$ip:1400/wifictrl?wifi=persist-off" 
    ping $ip -n 1 -w 1000 > nul 
    Invoke-RestMethod "http://$ip:1400/wifictrl?wifi=persist-off" 
} 
相關問題