Question
Create a data collection script using Python for Windows. The Python script will execute the DOS shell command, “netsh wlan show all” and parse the output to get all visible wifi SSIDs, MAC addresses, and signal strengths. Insert statements will need to be constructed to insert this information to two tables in a database.
Solution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references.
Students may use these solutions for personal skill-building and practice.
Unethical use is strictly forbidden.

import os
import re
import sys
import logging
import optparse
import MySQLdb
import subprocess

"""Script default configuration
"""
DB_HOST = '127.0.0.1'
DB_PORT = '3306'
DB_USER = 'wlanuser'
DB_PASS = 'wlanpass'
DB_NAME = 'wlandb'

class DB:
    """MySQL wrapper class
    """
    def __init__(self, ahost = DB_HOST, aport = DB_PORT, auser = DB_USER, apasswd = DB_PASS, adb = DB_NAME):
       """Initialize database configuration
       """
       self.conn = None
       self.host = ahost
       self.port = aport
       self.user = auser
       self.passwd = apasswd
       self.db = adb

    def connect(self):
       """Connect to database
       """
       self.conn = MySQLdb.connect(host=self.host,port=int(self.port),user=self.user,passwd=self.passwd,db=self.db,use_unicode=True, charset="utf8")
       self.conn.autocommit(True);
      
    def cursor(self):
       """Get current cursor of database
       """
       try:
            return self.conn.cursor()
       except (AttributeError, MySQLdb.OperationalError):
            self.connect()
            return self.conn.cursor()

    def escape(self, str):
       """Returns escaped string
       """
       if self.conn == None:
            self.connect()
       return self.conn.escape_string(str)
      
    def query(self, sql):
       """Query database with SQL statement
       """
       try:
            cursor = self.conn.cursor()
            cursor.execute(sql)
       except (AttributeError, MySQLdb.OperationalError):
            self.connect()
            cursor = self.conn.cursor()
            cursor.execute(sql)
       return cursor

    def close(self):
       """Close connection
       """
       if self.conn != None:
            self.conn.close()

    def commit(self):
       """Manual commit database operation
       """
       self.conn.commit()
   
def parse_command_line(argv):
    """Command line options parser for the script
    """
    usage = "usage: %prog [options]"
This is only a preview of the solution.
Please use the purchase button to see the entire solution.
By purchasing this solution you'll be able to access the following files:
Solution.py
Purchase Solution
$63.00
Google Pay
Amazon
Paypal
Mastercard
Visacard
Discover
Amex
View Available Computer Science Tutors 645 tutors matched
Ionut
(ionut)
Master of Computer Science
Hi! MSc Applied Informatics & Computer Science Engineer. Practical experience in many CS & IT branches.Research work & homework
5/5 (6,806+ sessions)
1 hour avg response
$15-$50 hourly rate
Pranay
(math1983)
Doctor of Philosophy (PhD)
Ph.D. in mathematics and working as an Assistant Professor in University. I can provide help in mathematics, statistics and allied areas.
4.6/5 (6,696+ sessions)
1 hour avg response
$40-$50 hourly rate
Leo
(Leo)
Doctor of Philosophy (PhD)
Hi! I have been a professor in New York and taught in a math department and in an applied math department.
4.9/5 (6,467+ sessions)
2 hours avg response

Similar Homework Solutions