問題描述:
我想下載特定網(wǎng)頁(yè)中包含的.pcap和.pcap.gz文件,使用bash腳本自動(dòng)完成,不需要手動(dòng)挨個(gè)點(diǎn)。
解決方案:
1. 下載網(wǎng)頁(yè)保存
curl -O -s https://wiki.wireshark.org/SampleCaptures
2. 提取網(wǎng)頁(yè)中的要下載的文件名稱
for i in `cat SampleCaptures | grep -hoir 'target=[a-zA-Z0-9_-]*.pcap'`
文件名特征是字母、數(shù)字、-、_這幾種字符組合而成,文件名叫做'target=xx.pcap'`,用正則就可以提取。
3. 組合url字符串并下載
base="https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=get&";for i in `cat SampleCaptures | grep -hoir 'target=[a-zA-Z0-9_-]*.pcap'`; do echo "downloading ${base}${i} ..."; curl -s -O "${base}${i}"; done