好的,我剛剛開始學習網絡安全,並且在此之前沒有掌握linux知識。我試圖編寫一個腳本,當你遵循tcp流,然後導出對象時,它將基本上完成wireshark中的GUI。我幾乎沒有任何編碼背景,我想知道最好的格式來做到這一點。一切工作完美,但後來我決定添加一個函數來測試與md5sum的原始輸出。我無法讓它工作。創建一個tshark bash腳本來導出對象
function testScript {
if [[ $test == "yes" ]]; then
echo "Type original file path: ";
read ogfpath;
md5sum "$fpath" "$ogfpath" > print
else
echo "Goodbye"
fi
}
echo -n 'Type stream number and press ENTER: '
read stream
echo -n 'Type pcap path and press ENTER: '
read pcap
echo -n 'Type magic number and press ENTER: '
read mnum
echo -n 'Type new file path and press ENTER: '
read fpath
tshark -2 -q -z follow,tcp,raw,$stream -r $pcap | tr '\n' ' ' | sed 's\ \\g' | grep -oP "(?<="$mnum").+" | sed "s/^/"$mnum"/g" | xxd -r -p > $fpath
echo -n 'Do you want to test the program (y/n)? :'
read test
testScript
函數中的'$ test'是[局部變量](http://tldp.org/LDP/abs/html/localvar.html)。 [見這裏](http://stackoverflow.com/questions/6212219/passing-parameters-to-a-bash-function)將參數傳遞給函數。 – miken32
還要注意你的引號在這裏有問題:'grep -oP「(?<=」$ mnum「)。+」'和here:sed''s/^ /「$ mnum」/ g「'。你會想逃離內在的。 – miken32