Hello Daniweb,
I am writing a program to execute the command prompt command "getmac /v >> MACLIST.txt" using a Visual Basic form, including: 2 buttons(getmac and filter the text file) , 2 textboxes (alternate text file name and user name), and two radiobuttons (default text file name or custom name).
Once I select the appropriate radiobutton and push the getmac /v button a text file is created with all of the MAC addresses of the PC.
I want to filter out the Wireless MAC addresses using "regex" or regular expressions.
The initial text file output looks like below:
______________________________________
COMPUTER: TESTMAC2-PC
______________________________________
Connection Name Network Adapter Physical Address Transport Name
=============== =============== =================== ==========================================================
Wireless Networ Broadcom 802.11 CC-11-FD-1E-7D-A9 \Device\Tcpip_{whatever}
Local Area Conn Atheros AR8132 18-A9-05-E7-84-79 \Device\Tcpip_{whatever}
Bluetooth Netwo Bluetooth Devic 00-11-22-33-44-55 Media disconnected
Local Area Conn TAP-Win32 Adapt 00-AA-59-57-36-39 Media disconnected
VirtualBox Host VMWare Host 00-00-23-20-7D-55 \Device\Tcpip_{whatever}
______________________________________
COMPUTER: TESTMAC1-PC
______________________________________
Connection Name Network Adapter Physical Address Transport Name
=============== =============== =================== ==========================================================
Wireless Networ Broadcom 802.11 CC-11-FD-1E-7D-A9 \Device\Tcpip_{whatever}
Local Area Conn Atheros AR8132 18-A9-05-E7-84-79 \Device\Tcpip_{whatever}
Bluetooth Netwo Bluetooth Devic 00-11-22-33-44-55 Media disconnected
Local Area Conn TAP-Win32 Adapt 00-AA-59-57-36-39 Media disconnected
VirtualBox Host VMWare Host 00-00-23-20-7D-55 \Device\Tcpip_{whatever}
What I want it to be filtered to look like is below:
______________________________________
COMPUTER: TESTMAC2-PC
______________________________________
Wireless Networ Broadcom 802.11 CC-11-FD-1E-7D-A9 \Device\Tcpip_{whatever}
______________________________________
COMPUTER: TESTMAC1-PC
______________________________________
Wireless Networ Broadcom 802.11 CC-11-FD-1E-7D-A9 \Device\Tcpip_{whateve}
Below is some of my Visual Basic 2008 code:
Imports System.Text.RegularExpressions
Imports System.IO
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, "USER: " & TextBox2.Text.Trim & vbNewLine & vbNewLine, True)
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, "USER: " & TextBox2.Text.Trim & vbNewLine & vbNewLine, True)
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
.THIS IS IF THE DEFAULT MACLIST.TXT RADIO BUTTON IS SELECTED
'HERE I WANT TO USE REGEX TO FILTER THE GETMAC OUTPUT
'I HAVE TO DELETE OR REPLACE THE LINES FROM "COMPUTER: " TO "Wireless etc... to the
'wireless mac address END OF THE LINE AND EVERY OTHER LINE WITH WIRELESS
'THE REST OF THE CODE (OR RADIOBUTTON2.CHECKED) IS SELF EXPLANATORY
Does anybody have any hints?
Thanks in advance,
m1234ike