0

I am kind of new to Python and trying to learn how to write an SSID Scanner that will do the following:

  1. Ask user for length of time to scan
  2. Enable Monitor Mode through Airmon-NG using a wlan
  3. Check to see if Mon0 is infact enabled, then goes to the next step
  4. After checking for Mon0, start Airmon-NG using Mon0 and scan for 5 minutes
  5. Have the program see that once the 5 minute mark is hit, print out "SSID Scan Complete"
  6. Close program

I'd like to eventually grab the scan output after 5 minutes and dump it into a text file for later viewing, but I'm not there yet, so excuse the Python ignorance as I continue to learn. All I have so far is after research, but I feel stuck and some parts I know are wrong and I cant figure them out, such as:

  1. actually verifing Mon0 is on before starting airodump-NG
  2. Waiting for the inputted time length before finishing

Here is what I have so far:

#!/usr/bin/env python

import os
import subprocess
from datetime import datetime

#Clear the screen
subprocess.call("clear")

#Ask for the length of time in Minutes to scan for SSIDs
scan_ssid = raw_input("How many minutes would you like to scan for: ")
scan_length = scan_ssid

#Print banner
print "Scanning for SSIDs for " + scan_ssid " minutes."

#Start and verify airmon-ng in monitor mode
print "Placing wlan iface in Monitor Mode"

os.system("airmon-ng start wlan2")

monitor = mon0

if monitor == True:
    print "Monitor Mode: Enabled"


#Start airodump-ng with monitor enabled
print "Starting SSID scan with Monitor Mode"

os.system("airodump-ng mon0")


#Scan for the user requested timefame
scan_length = time.time()
while True:
        scan_length = 0
        if scan_length == 5 or time.time() > scan_length:
            break
        scan_length = scan_length - 1
        print "SSID Scan Complete!"

sys.exit(0)
MattDMo
  • 100,794
  • 21
  • 241
  • 231
Sam
  • 11
  • 1
  • 1
  • 6
  • I'm also relatively new to python so I may not be of the most help but here's what I can offer. Aren't you `break`ing if the scan_length still has 5 minutes remaining? For sure though, I recommend taking a second look at the `while` loop. It took me a little while to understand the nuances of similar loops at first. As for verifying that the Mon0 is on, I recommend cross referencing the output of airmon-ng using an `if/else`. Then use `grep` on specific phrases or compare the raw results before and after. Awesome idea btw! I've always wanted to do something similar. Do you have a GitHub? –  Apr 06 '15 at 01:47
  • hmm, I see what you mean with the break part. I'm also trying to get a grip on the while loops. As far as the checking on the airmon-ng, I was thinking of a way to read the output, but the issue is I'm not sure how to parse through the output and find "mon0", because I figured that the script would be doing everything in the background and so I wouldnt really see anything. – Sam Apr 06 '15 at 01:54
  • I'm thinking maybe this would work: subprocess.check_output("mon0", shell=True), but not too sure – Sam Apr 06 '15 at 01:57
  • Yea I'm lost with that suggestion. I know it would work if you appended a basic text file with the raw output of the command (bypassing all the background stuff) then checked it for mon0 using `grep`. However this method has always felt a little "hardcoded" and I'm sure there is a better way I've just never looked too much into it. Still trying to learn and practice some of the simpler stuff. You learn by doing and debugging though, so keep at it. Very interested in seeing where you go with this script. –  Apr 06 '15 at 02:17

1 Answers1

0

You could look to run "ifconfig" in the shell command. If MON0 is listed you could then skip puting WLAN2 into wireless mode.

thefragileomen
  • 1,537
  • 8
  • 24
  • 40