Wireless LAN (WLAN)
There are many vendors that have backend APIs that can be controlled or called using Python to perform certain wireless tasks. A commonly used vendor in wireless is Netgear. Python has a library pynetgear that helps us achieve some of the automation to control our locally connected devices.
Let's see an example of fetching the current network devices connected to the local wireless Netgear router in our network:
>>> from pynetgear import Netgear, Device
>>> netgear = Netgear("myrouterpassword", "192.168.100.1","admin","80")
>>> for i in netgear.get_attached_devices():
print (i)
The Netgear method accepts four arguments in the following order (routerpassword, routerip, routerusername, and routerport). As we see in the current example, the router is reachable using http://192.168.100.1 with the username admin and password as myrouterpassword. Hence, we call the method with these parameters.
The output is shown as follows:
>>> netgear.get_attached_devices()
[Device(signal=3, ip='192.168.100.4', name='ANDROID-12345', mac='xx:xx:xx:xx:xx:xx', type='wireless', link_rate=72), Device(signal=None, ip='192.168.100.55', name='ANDROID-678910', mac='yy:yy:yy:yy:yy:yy', type='wireless', link_rate=72), Device(signal=None, ip='192.168.100.10', name='mylaptop', mac='zz:zz:zz:zz:zz:zz', type='wireless', link_rate=520)]
As we see, the method get_attached_devices() returned a list of all the IPs, their MAC addresses (hidden in this example), signal (or wireless band being used), and the link rate for the connection in Mbps.
We can use similar type of methods to manipulate bandwidth, block any user, or perform other tasks that are exposed by the APIs of the specific hardware manufacturer.