|
| 1 | +# Operating system functions. |
| 2 | +importos |
| 3 | +# Import all functions from scapy library. |
| 4 | +fromscapy.allimport* |
| 5 | +# Import Fore from colorama for colored console output, and init for colorama initialization. |
| 6 | +fromcoloramaimportFore,init |
| 7 | +# Initialize colorama |
| 8 | +init() |
| 9 | + |
| 10 | +# Set to store unique SSIDs. |
| 11 | +seen_ssids=set() |
| 12 | + |
| 13 | + |
| 14 | +# Function to set the wireless adapter to monitor mode. |
| 15 | +defset_monitor_mode(interface): |
| 16 | +# Bring the interface down. |
| 17 | +os.system(f'ifconfig{interface} down') |
| 18 | +# Set the mode to monitor. |
| 19 | +os.system(f'iwconfig{interface} mode monitor') |
| 20 | +# Bring the interface back up. |
| 21 | +os.system(f'ifconfig{interface} up') |
| 22 | + |
| 23 | + |
| 24 | +# Function to process Wi-Fi packets. |
| 25 | +defprocess_wifi_packet(packet): |
| 26 | +# Check if the packet is a Probe Request, Probe Response, or Association Request. |
| 27 | +ifpacket.haslayer(Dot11ProbeReq)orpacket.haslayer(Dot11ProbeResp)orpacket.haslayer(Dot11AssoReq): |
| 28 | +# Extract SSID and BSSID from the packet. |
| 29 | +ssid=packet.info.decode('utf-8',errors='ignore') |
| 30 | +bssid=packet.addr3 |
| 31 | + |
| 32 | +# Check if the SSID is not empty and not in the set of seen SSIDs, and if the BSSID is not the broadcast/multicast address. |
| 33 | +ifssidandssidnotinseen_ssidsandbssid.lower()!='ff:ff:ff:ff:ff:ff': |
| 34 | +# Add the SSID to the set. |
| 35 | +seen_ssids.add(ssid) |
| 36 | +# Print the identified SSID and BSSID in green. |
| 37 | +print(f"{Fore.GREEN}[+] SSID:{ssid} ----> BSSID:{bssid}") |
| 38 | + |
| 39 | + |
| 40 | +# Main function. |
| 41 | +defmain(): |
| 42 | +# Define the wireless interface. |
| 43 | +wireless_interface='wlan0' |
| 44 | + |
| 45 | +# Set the wireless adapter to monitor mode. |
| 46 | +set_monitor_mode(wireless_interface) |
| 47 | + |
| 48 | +# Print a message indicating that sniffing is starting on the specified interface in magenta. |
| 49 | +print(f"{Fore.MAGENTA}[+] Sniffing on interface:{wireless_interface}") |
| 50 | + |
| 51 | +# Start sniffing Wi-Fi packets on the specified interface, calling process_wifi_packet for each packet, and disabling packet storage |
| 52 | +sniff(iface=wireless_interface,prn=process_wifi_packet,store=0) |
| 53 | + |
| 54 | + |
| 55 | +# Check if the script is being run as the main program. |
| 56 | +if__name__=="__main__": |
| 57 | +# Call the main function. |
| 58 | +main() |