How To Scan Network Using Python On Raspberry Pi / How to Detect Wi-Fi devices on Raspberry Pi

In todays tutorial we will learn how to scan all available Wi-Fi networks on Raspberry Pi Device.


Introduction to Nmap

Nmap (Network Mapper) is a security scanner, used to discover hosts and services on a computer network, thus building a "map" of the network. To accomplish its goal, Nmap sends specially crafted packets to the target host(s) and then analyzes the responses.


Steps

In tutorial we will follow basic mentioned steps,
  1. Install Nmap on Raspberry Pi
  2. Find Gateway Ip of Pi
  3. Python code to detect Particular device


Install Map on Raspberry Pi 

To Install Nmap on Raspberry Pi simply run below command,
sudo apt-get install nmap


Find below image for reference of installation process,


Find IP Address of Gateway Device

To find IP address of Gateway device run below command,
route | grep default

Find below image for reference,  




To find IP address of Raspberry PI device run below command,
ifconfig

Python code to detect Particular device 

Use below python script to find particular device from network. Modify mac1 and mac2 with your intended devices mac address and run script.
import subprocess 
mac1="A0:F3:C1:E2:33:8E" 
mac2="F0:79:60:2B:1A:E4" result=subprocess.check_output("sudo nmap -sn 192.168.0.1-255", shell=True) 
print(result) 
if (mac1 in result):         
     print("1st device found on network")
if (mac2 in result):         
     print("2st device found on network")  

Below image is shows execution of above python script.




You can download above python script here.


You may also check our other posts at 

Post a Comment

0 Comments