Hello Daniweb,

I am writing an App that uses two buttons, two radiobuttons, and a textbox to use the Windows shell command to print the "getmac" command to a text file: i.e.
"getmac /v >> whatever.txt"

I want to save the "wireless" MAC addresses to a text file from a bunch of computers with this app.

i.e. output:

COMPUTER: name-PC
_________________________________________


WIRELESS MAC: 00-22-03-FF-EE-DD


_________________________________________
COMPUTER: nameTwoXP-PC
_________________________________________
WIRELESS MAC: 00-00-FF-32-55-33

and so on by the ">>" symbol in the shell command "getmac \v >> text.txt " and true at the end of the writeAllText (...., true) appends each next PC on to the list.

This app can be great for computer WIFI inventories.

What I need is some code to use the second button to filter out the lines with "wireless" to the end of the that line (which includes the WIFI MAC Address) and then delete everything else until the delimiter "COMPUTER: ".

I have played with the code and below is what I have used so far to get the WIFI MACs but I do not think the output is clean enough.

Any hints?

My code is below:
______________________________________________________________________

Imports System.Text.RegularExpressions
Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If RadioButton2.Checked = True Then


Dim name As String = My.Computer.Name
Dim path As String = My.Computer.FileSystem.CurrentDirectory & "\MACLIST.txt"
My.Computer.FileSystem.WriteAllText(path, "______________________________________" & vbNewLine & vbNewLine, True)
My.Computer.FileSystem.WriteAllText(path, "COMPUTER: " & name & vbNewLine, True)
' My.Computer.FileSystem.CurrentDirectory &
Shell("cmd.exe /c getmac /v >> MACLIST.txt", AppWinStyle.MaximizedFocus)
My.Computer.FileSystem.WriteAllText(path, "______________________________________" & vbNewLine & vbNewLine, True)



ElseIf RadioButton1.Checked = True Then
TextBox1.Enabled = True
If String.IsNullOrEmpty(TextBox1.Text.Trim()) Or TextBox1.Text.Contains(".") Then
MsgBox("Please enter a valid output file name")
Else
Dim name1 As String = My.Computer.Name
Dim path1 As String = My.Computer.FileSystem.CurrentDirectory & "\" & TextBox1.Text.Trim & ".txt"
My.Computer.FileSystem.WriteAllText(path1, "______________________________________" & vbNewLine & vbNewLine, True)
My.Computer.FileSystem.WriteAllText(path1, "COMPUTER: " & name1 & vbNewLine, True)
' My.Computer.FileSystem.CurrentDirectory &


Shell("cmd.exe /c getmac /v >> " & TextBox1.Text.Trim & ".txt", AppWinStyle.MaximizedFocus)
My.Computer.FileSystem.WriteAllText(path1, "______________________________________" & vbNewLine & vbNewLine, True)



End If
End If


TextBox1.Enabled = True


Button2.Select()



End Sub



Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked = True Then
TextBox1.Enabled = False
ElseIf RadioButton1.Checked = True Then
TextBox1.Enabled = True



End If



End Sub


Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


If RadioButton1.Checked = True Then



'"([0-9a-fA-F][0-9a-fA-F]-){5}([0-9a-fA-F][0-9a-fA-F])"
Dim fso, inputFile, outputFile
Dim str As String


fso = CreateObject("Scripting.FileSystemObject")


'1 means for reading


inputFile = fso.OpenTextFile(TextBox1.Text.Trim & ".txt", 1)


str = inputFile.ReadAll


'modify this string, replace required characters


str = Replace(str, "Wireless", "_______________________________" & vbNewLine & "******WIRELESS Next Line******" & vbNewLine & "_______________________________" & vbNewLine)
str = Replace(str, "Connection Name Network Adapter Physical Address    Transport Name ", "")
str = Replace(str, "=============== =============== ===================", "")
str = Replace(str, "==========================================================", "")


'write back


outputFile = fso.CreateTextFile(TextBox1.Text.Trim & ".txt", True)


outputFile.Write(str)
ElseIf RadioButton2.Checked = True Then
Dim a As String



Dim fso, inputFile, outputFile
Dim str As String


fso = CreateObject("Scripting.FileSystemObject")


'1 means for reading


inputFile = fso.OpenTextFile("MACLIST.txt", 1)


str = inputFile.ReadAll


'modify this string, replace required characters


str = Replace(str, "Wireless", "_______________________________" & vbNewLine & "******WIRELESS Next Line******" & vbNewLine & "_______________________________" & vbNewLine)
str = Replace(str, "Connection Name Network Adapter Physical Address    Transport Name ", "")
str = Replace(str, "=============== =============== ===================", "")
str = Replace(str, "==========================================================", "")
'str = Replace(str, , "")


'write back


outputFile = fso.CreateTextFile("MACLIST.txt", True)


outputFile.Write(str)
'System.Diagnostics.Process.Start("MACLIST.txt")
End If


End Sub



End Class

Thanks in advance,
m1234ike

Recommended Answers

All 2 Replies

Wow, I think you are making this way more complicated than it should be. Most of this can be done with batch files easier than with vb.

1. First off you haven't shown how to get the computer name.
echo COMPUTER: %COMPUTERNAME% >>txtfile.txt

2. have the getmac command ( Assuming windows 7 ) get rid of the trash for you.
getmac /FO csv /NH >>txtfile.txt
This will give you one line comma delimited with the mac first and device id second.

we could probably combine all of this into a very small batch file to have it printout computername,mac if we tried hard enough

Hello Daniweb,

The reason I need the delimeter is to filter out the Wireless MAC or MACs.

I want to cleanup the output of the text file to simply show the Wireless adapter lines.

The text file printout is in a table format but as a text file it can be cleaned up line-by-line.

I want just the Wireless MACs for a networking reason or to enter MACs for "MAC Address Filtering".

Any hints?

Thannks in advance,

m1234ike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.