Skip to content

Commit 68a2a97

Browse files
committed
added wifi scanner tutorial
1 parent 81535f5 commit 68a2a97

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This is a repository of all the tutorials of [The Python Code](https://www.thepy
1313
- [Simple Network Scanner](https://www.thepythoncode.com/article/building-network-scanner-using-scapy). ([code](scapy/network-scanner))
1414
- [Writing a DNS Spoofer](https://www.thepythoncode.com/article/make-dns-spoof-python). ([code](scapy/dns-spoof))
1515
- [How to Sniff HTTP Packets in the Network using Scapy in Python](https://www.thepythoncode.com/article/sniff-http-packets-scapy-python). ([code](scapy/http-sniffer))
16+
- [How to Build a WiFi Scanner in Python using Scapy](https://www.thepythoncode.com/article/building-wifi-scanner-in-python-scapy). ([code](scapy/wifi-scanner))
1617
- [Writing a Keylogger in Python from Scratch](https://www.thepythoncode.com/article/write-a-keylogger-python). ([code](ethical-hacking/keylogger))
1718
- [Making a Port Scanner using sockets in Python](https://www.thepythoncode.com/article/make-port-scanner-python). ([code](ethical-hacking/port_scanner))
1819
- [How to Create a Reverse Shell in Python](https://www.thepythoncode.com/article/create-reverse-shell-python). ([code](ethical-hacking/reverse_shell))

Diff for: scapy/wifi-scanner/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# [How to Build a WiFi Scanner in Python using Scapy](https://www.thepythoncode.com/article/building-wifi-scanner-in-python-scapy)
2+
To run this:
3+
- `pip3 install -r requirements.txt`
4+
- Scan nearby networks using `wlan0mon` interface:
5+
```
6+
python wifi_scanner.py wlan0mon
7+
```

Diff for: scapy/wifi-scanner/requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pandas
2+
scapy

Diff for: scapy/wifi-scanner/wifi_scanner.py

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
from scapy.all import *
2+
from threading import Thread
3+
import pandas
4+
import time
5+
import os
6+
7+
8+
# initialize the networks dataframe that will contain all access points nearby
9+
networks = pandas.DataFrame(columns=["BSSID", "SSID", "dBm_Signal", "Channel", "Crypto"])
10+
# set the index BSSID (MAC address of the AP)
11+
networks.set_index("BSSID", inplace=True)
12+
13+
def callback(packet):
14+
if packet.haslayer(Dot11Beacon):
15+
# extract the MAC address of the network
16+
bssid = packet[Dot11].addr2
17+
# get the name of it
18+
ssid = packet[Dot11Elt].info.decode()
19+
try:
20+
dbm_signal = packet.dBm_AntSignal
21+
except:
22+
dbm_signal = "N/A"
23+
# extract network stats
24+
stats = packet[Dot11Beacon].network_stats()
25+
# get the channel of the AP
26+
channel = stats.get("channel")
27+
# get the crypto
28+
crypto = stats.get("crypto")
29+
networks.loc[bssid] = (ssid, dbm_signal, channel, crypto)
30+
31+
32+
def print_all():
33+
while True:
34+
os.system("clear")
35+
print(networks)
36+
time.sleep(0.5)
37+
38+
39+
def change_channel():
40+
ch = 1
41+
while True:
42+
os.system(f"iwconfig {interface} channel {ch}")
43+
# switch channel from 1 to 14 each 0.5s
44+
ch = ch % 14 + 1
45+
time.sleep(0.5)
46+
47+
48+
if __name__ == "__main__":
49+
# interface name, check using iwconfig
50+
interface = "wlan0mon"
51+
# start the thread that prints all the networks
52+
printer = Thread(target=print_all)
53+
printer.daemon = True
54+
printer.start()
55+
# start the channel changer
56+
channel_changer = Thread(target=change_channel)
57+
channel_changer.daemon = True
58+
channel_changer.start()
59+
# start sniffing
60+
sniff(prn=callback, iface=interface)

0 commit comments

Comments
 (0)