![]() |
|
|||||||
| Register | Search | Today's Posts | Mark Forums Read |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#1 (permalink) |
|
Posts: n/a
|
Script To Parse the OUI.TXT file with Visual Basic (in Microsoft Access)
I threw this together to help with one of my projects. It may help you also. I'm storing my APs in an MS Access database. I needed a table to relate the MAC IDs to the BSSID in the FoundAP table. Creating it the first time is easy enough, but when the table needs to be updated, this Sub can be run and it will do it for you. Be warned, it runs very slow, taking about five minutes to parse all 9,374 records. Strings are slow as hell, at least in VB. Under ASP/VBScript this would run much faster, I believe.
Modify as needed. Enjoy! Code:
Sub UpdateOUI()
' This will parse the OUI.txt file located at http://standards.ieee.org/regauth/oui/oui.txt
' This version does not grab the file automatically. You'll have to download it and place it
' somewhere that's accessible by this code. I have made a separate version that uses Microsoft's
' XML parser to download the file automatically AND parse it (useful for automated scripts run daily).
' This version is for the few people that may not have the XML parser installed on their system.
' Create a FSO.
Set fso = CreateObject("Scripting.FileSystemObject")
' Open the file. Change the path to where you have your file saved.
Set ts = fso.OpenTextFile("C:\OUI\OUI.txt")
' The first six lines contain nothing useful to us, so we skip them.
For i = 1 To 6
ts.SkipLine
Next
' Any line that contains (hex) in it has the info we need.
Do While Not ts.AtEndOfStream
tvar = ts.ReadLine
If Mid(tvar, 12, 5) = "(hex)" Then
Dim MMACID As String
Dim Company As String
MMACID = Replace(Left(tvar, 8), "-", "")
Company = Replace(Mid(tvar, 19), "'", "''")
Dim rs As Recordset
Set rs = CurrentDb.OpenRecordset("SELECT MACID FROM OUI WHERE MACID = '" & MMACID & "'")
If rs.EOF Then
CurrentDb.Execute "INSERT INTO OUI (MACID, Company) VALUES ('" & MMACID & "', '" & Company & "')"
End If
End If
Loop
'Tidy up after ourselves.
ts.Close
Set ts = Nothing
rs.Close
Set rs = Nothing
End Sub
|
|
|
|
#2 (permalink) | |
|
root\.workspace\.garbage.
Join Date: Aug 2003
Posts: 4,789
|
Quote:
move your DIM outside of the loop so you declare them once and not everytime you go through the loop. The real memory hog and slowness is creating a hook into your database every time you want to add a record. Instead of using opensrecordset and insert consider adding a WHERE clause to your insert statment.
__________________
It's not Intelligent Design, it's peer pressure. ┌──────────────────────────────┐ ╞ NS Icons Explained|et hoc genus omne ╡ └──────────────────────────────┘ |
|
|
|
|
|
|
#4 (permalink) |
|
Posts: n/a
|
Thanks for the tips.
I moved the Dim statements outside of the loop (not sure why I put them inside, other than I threw this together in 5 min) but it still runs dog slow due to the recordset lookup. I wasn't sure what you meant by using a WHERE clause in the INSERT statement. How would I do that? |
|
|
|
#5 (permalink) | |
|
Psychic Amish Stumbler
Join Date: Jul 2004
Location: Virginville, BlueBall, Bird In Hand, Intercourse, Paradise, PA
Posts: 11,790
|
Quote:
If you're inserting it, then you're creating the record, you can do a WHERE in the UPDATE, but I've never see one on a INSERT. I could be wrong, never claimed to know everything about SQL.
__________________
"One of these days, I'm going to cut you to pieces." If you're offended by this post, please feel free to report it to one of the many helpful moderators of this forum. Thank you. |
|
|
|
|
|
|
#6 (permalink) | |
|
root\.workspace\.garbage.
Join Date: Aug 2003
Posts: 4,789
|
Quote:
Normally you'd open a connection to the table then use a select statement to return a true/false then perform an update/insert based on the conditions. There are more elequeont ways of doing this rather then they method you're using.
__________________
It's not Intelligent Design, it's peer pressure. ┌──────────────────────────────┐ ╞ NS Icons Explained|et hoc genus omne ╡ └──────────────────────────────┘ |
|
|
|
|
|
|
#7 (permalink) | |
|
Knight Tooth Puller
Join Date: Aug 2004
Location: Bellevue, WA, USA
Posts: 182
|
Quote:
If you're unfamiliar with Scripting.Dictionary, look at the Master Script's ns04speech.vbs: adding at OnScanResultSpeech, regurgitating at OnScanCompleteSpeech. ns04database.vbs also has some potentially useful code. Obviously MSDN et al have more info. [1]Assuming the language you're using exposes Scripting.Dictionary. You're using Dim with types, so my early assumption of vbscript was incorrect. [2]Is an OUI listing with duplicates valid? Last edited by goldfndr : 06-28-2006 at 05:43 AM. |
|
|
|
|