B
B
Bogdan38282022-03-13 12:36:13
Python
Bogdan3828, 2022-03-13 12:36:13

Searching for a channel from the log using regular expressions?

There is such a log after executing the command
iwlist wlp2s0 scan > wifiscan.log
After the user enters the WI-FI MAC address, you need to display the channel number of the access point ...

mac_ = input("Enter mac addres: ")
???

How can I parse the channel number using the re module?
wlp2s0    Scan completed :
          Cell 01 - Address: 00:11:22:33:44:55
                    Channel:3
                    Frequency:2.422 GHz (Channel 3)
                    Quality=39/70  Signal level=-71 dBm  
                    Encryption key:on
                    ESSID:"My Network"
                    Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 9 Mb/s
                              18 Mb/s; 36 Mb/s; 54 Mb/s
                    Bit Rates:6 Mb/s; 12 Mb/s; 24 Mb/s; 48 Mb/s
                    Mode:Master
                    Extra:tsf=00000035026f3a00
                    Extra: Last beacon: 64ms ago
                    IE: Unknown: 000A546167746162617A6172
                    IE: Unknown: 010882848B961224486C
                    IE: Unknown: 030103
                    IE: Unknown: 2A0100
                    IE: Unknown: 32040C183060
                    IE: Unknown: 2D1AEC1117FFFF000001000000000000000000000000000000000000
                    IE: Unknown: 3D1603000000000000000000000000000000000000000000
                    IE: IEEE 802.11i/WPA2 Version 1
                        Group Cipher : CCMP
                        Pairwise Ciphers (1) : CCMP
                        Authentication Suites (1) : PSK
                    IE: Unknown: 7F080000000100000000
                    IE: Unknown: DD180050F2020101000003A4000027A4000042435E0062322F00
                    IE: Unknown: 4A0E14000A002C01C800140005001900
                    IE: Unknown: 7F080000000100000000
                    IE: Unknown: DD740050F204104A0001101044000102103B00010310470010BC329E001DD811B2860134E894E04BC61021000754502D4C494E4B102300044144534C102400065254323836301042000831323334353637381054000800060050F20400011011000954442D57383936314E100800020084103C000101
                    IE: Unknown: DD07000C4300000000

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2022-03-13
@Bogdan3828

iwlist wlp2s0 scan | grep -oP "(?<=Channel:)\d+"

K
ky0, 2022-03-13
@ky0

Why do you need regular expressions here, if you can just rattle on the necessary parameter names and then reveal the excess with some kind of awk?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question