Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # # iwlist wlan0 scan | bash wifi.sh
- # http://stackoverflow.com/questions/25394772/parsing-iwlist-scan-using-bash
- ## print header lines
- #echo ""
- #echo " mac essid frq chn qual lvl enc ie protocol bitRates groupCipher authenticationSuites"
- cat <<EOF
- {
- "wifi" : [
- EOF
- while IFS= read -r line; do
- ## test line contenst and parse as required
- [[ "$line" =~ Address ]] && mac=${line##*ss: }
- [[ "$line" =~ 'Bit Rates' ]] && bitRates=${line##*Bit Rates:}
- [[ "$line" =~ 'Group Cipher' ]] && groupCipher=${line##*Group Cipher :}
- [[ "$line" =~ 'Authentication Suites' ]] && authenticationSuites=${line##*Authentication Suites (*) :}
- [[ "$line" =~ Protocol ]] && protocol=${line##*Protocol:}
- [[ "$line" =~ IE: ]] && ie=${line##*IE: }
- [[ "$line" =~ \(Channel ]] && { chn=${line##*nel }; chn=${chn:0:$((${#chn}-1))}; }
- [[ "$line" =~ Frequen ]] && { frq=${line##*ncy:}; frq=${frq%% *}; }
- [[ "$line" =~ Quality ]] && {
- qual=${line##*ity=}
- qual=${qual%% *}
- lvl=${line##*evel=}
- lvl=${lvl%% *}
- }
- [[ "$line" =~ Encrypt ]] && enc=${line##*key:}
- [[ "$line" =~ ESSID ]] && {
- essid=${line##*ID:}
- #echo " $mac | $essid | $frq | $chn | $qual | $lvl | $enc | $ie | $protocol | $bitRates | $groupCipher | $authenticationSuites" # output after ESSID
- cat <<EOF
- {
- "ssid" : $essid,
- "bssid" : "$mac",
- "freq" : $frq,
- "channel" : $chn ,
- "signal_level" : "$lvl",
- "quality" : "$qual",
- "enc" : "$enc",
- "ie" : "$ie",
- "protocol" : "$protocol",
- "bit_rates" : "$bitRates",
- "group_cipher" : "$groupCipher",
- "authenticationSuites" : "$authenticationSuites"
- },
- EOF
- }
- done
- echo " ] }"
Advertisement
Add Comment
Please, Sign In to add comment