Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to find the no of user for a wifi using python for ubuntu

"""
Search for a specific wifi ssid and connect to it.
written by kasramvd.
"""
import os


class Finder:
    def __init__(self, *args, **kwargs):
        self.server_name = kwargs['server_name']
        self.password = kwargs['password']
        self.interface_name = kwargs['interface']
        self.main_dict = {}

    def run(self):
        command = """sudo iwlist wlp2s0 scan | grep -ioE 'ssid:"(.*{}.*)'"""
        result = os.popen(command.format(self.server_name))
        result = list(result)

        if "Device or resource busy" in result:
                return None
        else:
            ssid_list = [item.lstrip('SSID:').strip('"
') for item in result]
            print("Successfully get ssids {}".format(str(ssid_list)))

        for name in ssid_list:
            try:
                result = self.connection(name)
            except Exception as exp:
                print("Couldn't connect to name : {}. {}".format(name, exp))
            else:
                if result:
                    print("Successfully connected to {}".format(name))

    def connection(self, name):
        try:
            os.system("nmcli d wifi connect {} password {} iface {}".format(name,
       self.password,
       self.interface_name))
        except:
            raise
        else:
            return True

if __name__ == "__main__":
    # Server_name is a case insensitive string, and/or regex pattern which demonstrates
    # the name of targeted WIFI device or a unique part of it.
    server_name = "example_name"
    password = "your_password"
    interface_name = "your_interface_name" # i. e wlp2s0  
    F = Finder(server_name=server_name,
               password=password,
               interface=interface_name)
    F.run()
Comment

PREVIOUS NEXT
Code Example
Python :: python filter list 
Python :: where are docker logs 
Python :: dbscan python 
Python :: How to convert datetime in python 
Python :: query first 5 element in django 
Python :: cannot create group in read-only mode. keras 
Python :: django convert model to csv 
Python :: Python - Comment lire une ligne de fichier par ligne 
Python :: pytorch torchaudio torchvision cu113 
Python :: python print ling line in print 
Python :: assignment 6.5 python for everybody 
Python :: plotting mean in density plot ggplot2 
Python :: python open file check error 
Python :: pyhton comment 
Python :: create folders in python overwright existing 
Python :: .size pandas 
Python :: python replace in string 
Python :: class chain methods python 
Python :: get coordinates of an image from a pdf python 
Python :: *kwargs 
Python :: request.args.get check if defined 
Python :: python background process 
Python :: PySimpleGUI all elements 
Python :: how to delete in python 
Python :: how to pre populate field flask wtforms 
Python :: python save images from directory to list 
Python :: python remove white space 
Python :: format numbers in column to percentage in python 
Python :: Python remove duplicate lines from a text file 
Python :: sns swarm plot 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =