QuestionQuestion

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 PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse 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]"...
$63.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats