Jacky
Jacky

Reputation: 336

How to capture wifi packets with a specific channel using Pyshark?

I use codes below to capture wifi packets, and save the pcap file to a text file.

However in the text file it only shows packets with channel 1, even no channel 2 or more.

I'm using python2.7 and pyshark-0.3.8 .

    capture = pyshark.LiveCapture(interface = network_card +'mon',output_file=pathfile +'.pcap')
    capture.set_debug()
    capture.sniff(timeout = scanner_time)
    list = str(capture).split('(')[1]
    list1 = list.split(' ')[0]
    print(list1)
    with open(pathfile +'.txt', 'w') as f:
        for pkt in range(int(list1)):
            f.write(str(capture[pkt]))

Is there any way to capture from a specific channel not just channel 1?

The image is a part of a packet in the text file which shows current channel.

image

Upvotes: 0

Views: 1017

Answers (1)

Jacky
Jacky

Reputation: 336

I found this command that can change network card in monitor mode and switch to a certain channel.

sudo airmon-ng start 'network_card' 'channel'

Then run the code in my question, pyshark will search the channel you input.

When you want to stop monitoring, just type below:

sudo airmon-ng stop 'network_card'+'mon'

Upvotes: 0

Related Questions