0

I'm new to Python, but I'm convinced that you should learn by doing. So here goes:

I'm trying to create a small CLI-application that takes two textfiles as input. It's then supposed to create a list of common SSIDs from the file SSID.txt, and then go through Kismet.nettxt to see how many of the Access Points that have common names.

Am I on the right track here at all? This is what I have so far, which imports the SSID.txt into a variable called "ssids"

f = open('SSID.txt', "r")
s = open('Kismet.nettxt', "r")


for line in f:
    ssids = line.strip()



s.close()
f.close()

Any tips on how I should proceed from here and what to look for?

This is how the files are formatted:

SSID.txt:

linksys
<no ssid>
default
NETGEAR
Wireless
WLAN
Belkin54g
MSHOME
home
hpsetup
smc
tsunami
ACTIONTEC
orange
USR8054
101
tmobile
<hidden ssid>
SpeedStream
linksys-g
3Com

This is how the Kismet.nettxt is formatted:

Network 3: BSSID REMOVED
 Manuf      : Siemens
 First      : Sun Dec 29 20:59:46 2013
 Last       : Sun Dec 29 20:59:46 2013
 Type       : infrastructure
 BSSID      : REMOVED
   SSID 1
    Type       : Beacon
    SSID       : "Internet" 
    First      : Sun Dec 29 20:59:46 2013
    Last       : Sun Dec 29 20:59:46 2013
    Max Rate   : 54.0
    Beacon     : 10
    Packets    : 2
    Encryption : WPA+PSK
    Encryption : WPA+TKIP
 Channel    : 5
 Frequency  : 2432 - 2 packets, 100.00%
 Max Seen   : 1000
 LLC        : 2
 Data       : 0
 Crypt      : 0
 Fragments  : 0
 Retries    : 0
 Total      : 2
 Datasize   : 0
 Last BSSTS : 
    Seen By : wlan0 (wlan0mon)
6
  • 1
    Could you post an example of how the files are formatted? Commented Dec 30, 2013 at 17:13
  • @IanAuld I have added formatting :) Commented Dec 30, 2013 at 17:20
  • I'm not really familiar with .nettext, what value in kismet.nettext should be compared to the value form ssid? Commented Dec 30, 2013 at 17:33
  • Define "common" SSIDs in context with SSID.txt and Access point in context with Kismet.nettxt? Names of Access points are SSIDs? Commented Dec 30, 2013 at 17:37
  • The value from SSID.txt should be compared to the line " SSID : "Internet"" from Kismet.nettxt. @BleedingFinger Yes, the name of Access Points are called SSID. If you use a common SSID, it is possible to find precomputed cracking tables which will speed up password cracking considerably. SSID.txt is just a list of common SSIDs. If that make any sense? :) Commented Dec 30, 2013 at 17:40

2 Answers 2

1

Here are a couple of tips of how I would go about it.

  1. Read SSID.txt, create a dict of names, so you have something fast to lookup each name and store a count. This also removes the duplicates if there are any in the SSID.txt file.
  2. Read Kismet.nettxt, if line starts with has "SSID :" then take the name and lookup in the dict, if found add to the count.
  3. At this point you will have an ssids dictionary with the name and count.

The code would look something like this:

f = open('SSID.txt', "r")
s = open('Kismet.nettxt', "r")

ssids = {}  # Create dictionary

for line in f:
    # Add each to the dictionary, 
    # if there are duplicates this effectively removes them
    ssids[line.strip()] = 0

for line in s:

    # Check the lines in the kismet file that start with the SSID we are after
    if line.strip().startswith('SSID       :'):

        # Break the entry at : and take the second part which is the name
        kismet = line.split(':')[1].strip()

        # Remove the " marks from front and back and lookup in the ssids
        # add to the count if you find it.
        if kismet[1:-1] in ssids:
            ssids[kismet[1:-1]] += 1

s.close()
f.close()
Sign up to request clarification or add additional context in comments.

Comments

0

This code should do everything you asked for in the OP:

try:
    with open('SSID.txt', 'r') as s:
        ssid_dict = {}
        for each_line in s:
            ssid_dict[each_line.strip()] = 0 #key: SSID value: count
except FileNotFoundError:
    pass

try:
    with open('kissmet.nettext', 'r') as f:
        try:
            for each_line in f:
                each_line = each_line.strip()
                if each_line.startswith("SSID") and ':' in each_line: #checks for a line that starts with 'SSID' and contains a ':'
                    val = each_line.split(':')[1].replace('"', '').strip() #splits the line to get the SSID, removes the quotes
                    if ssid_dict[val]:
                        ssid_dict[val] += 1 #adds one to the count in the dictionary
                    else:
                        pass#I don't know what you want to do here
        except KeyError as err:
            print("Key error" + str(err))
except FileNotFoundError:
    pass

for key in ssid_dict:
    print(str(key) + " " + str(ssid_dict[key]))

it outputs:

Wireless 0
101 0
Belkin54g 0
tsunami 0
tmobile 0
<hidden ssid> 0
linksys-g 0
smc 0
hpsetup 0
ACTIONTEC 0
SpeedStream 0
Internet 1
3Com 0
home 0
USR8054 0
<no ssid> 0
WLAN 0
NETGEAR 0
default 0
MSHOME 0
linksys 0
orange 0

I added 'Internet' to the list of SSID's for testing purposes.

EDIT: I have updated the section that adds to the count to deal with keys that aren't in the dictionary. I don't knwo what you want to do with ones that aren't so for now I left a pass in there

4 Comments

Thanks a lot @IanAuld, it doesn't output it yet. But I'll tinker with it and get it running. Thanks! :) The error I get is: nick@crunchbang:~/downloads$ python ssid.py Key error'EpsonNet' 0
@user2956248 It looks like it's looking for a key that isn't in the dictionary.
Oh, that would make sense. "EpsonNet" is the name of the first SSID in the Kismet.nettxt file (and it doesn't exist in SSID.txt). So it should just skip that, is there any way to make that happen?
Don't forget to accept this as an answer by clicking the check mark next to the post. Good luck in learning!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.