473,322 Members | 1,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Regular Expression Problem

I'm trying to parse the output of ipconfig /all to retrieve the first MAC address that is not part of a VM adapter and the second byte should not be 50. A sample return is as follows: I'm able to retrieve just the MAC addresses and I'm able to discard them if 50 is in the second byte, but how do I determine if the word 'VMware' is in the immediately preceding description field and if so, enforce that no match is made.

Thanks.

Regular Expression:
..{2}-(?!50).{2}-.{2}-.{2}-.{2}-.{2}

Windows IP Configuration

Host Name . . . . . . . . . . . . : ws-remote
Primary Dns Suffix . . . . . . . : nothing.com
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
DNS Suffix Search List. . . . . . : nothing.com

Ethernet adapter VMware Network Adapter VMnet8:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for
VMnet8
Physical Address. . . . . . . . . : 00-50-56-C0-00-08
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.222.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :

Ethernet adapter VMware Network Adapter VMnet1:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for
VMnet1
Physical Address. . . . . . . . . : 00-50-56-C0-00-01
Dhcp Enabled. . . . . . . . . . . : No
IP Address. . . . . . . . . . . . : 192.168.17.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : SiS 900 PCI Fast Ethernet Adapter
Physical Address. . . . . . . . . : 00-0A-E6-AD-4B-B7
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 192.168.0.200
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
DHCP Server . . . . . . . . . . . : 192.168.0.10
DNS Servers . . . . . . . . . . . : 192.168.0.10
Lease Obtained. . . . . . . . . . : Sunday, November 02, 2003 8:44:31 AM

Lease Expires . . . . . . . . . . : Monday, November 10, 2003 8:44:31 AM

Nov 22 '05 #1
2 2698
"Stevo" <sp***********@cox.net> wrote in
news:eW*************@tk2msftngp13.phx.gbl:
I'm trying to parse the output of ipconfig /all to retrieve the
first MAC address that is not part of a VM adapter and the
second byte should not be 50. A sample return is as follows:
I'm able to retrieve just the MAC addresses and I'm able to
discard them if 50 is in the second byte, but how do I determine
if the word 'VMware' is in the immediately preceding description
field and if so, enforce that no match is made.


Stevo,

You can get both the Description and Physical Address w/ one regex.

string re =
@"Description.*?:\s*(?<description>.*?)\r\n" +
".*?Physical Address.*?:\s*(?<MAC>.*?)\r\n";

// "text" contains the Windows IP Config text.
MatchCollection mc = Regex.Matches(text, re,
RegexOptions.Singleline);

string description;
string MAC;
foreach(Match m in mc)
{
description = m.Groups["description"].ToString();
MAC = m.Groups["MAC"].ToString();

if (Regex.IsMatch(description, "vmware", RegexOptions.IgnoreCase))
continue;

Console.WriteLine(description);
Console.WriteLine(MAC);
}
In a DOS prompt, this will print:

SiS 900 PCI Fast Ethernet Adapter
00-0A-E6-AD-4B-B7
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 22 '05 #2
"Stevo" <sp***********@cox.net> wrote in
news:eW*************@tk2msftngp13.phx.gbl:
I'm trying to parse the output of ipconfig /all to retrieve the
first MAC address that is not part of a VM adapter and the
second byte should not be 50. A sample return is as follows:
I'm able to retrieve just the MAC addresses and I'm able to
discard them if 50 is in the second byte, but how do I determine
if the word 'VMware' is in the immediately preceding description
field and if so, enforce that no match is made.


Stevo,

You can get both the Description and Physical Address w/ one regex.

string re =
@"Description.*?:\s*(?<description>.*?)\r\n" +
".*?Physical Address.*?:\s*(?<MAC>.*?)\r\n";

// "text" contains the Windows IP Config text.
MatchCollection mc = Regex.Matches(text, re,
RegexOptions.Singleline);

string description;
string MAC;
foreach(Match m in mc)
{
description = m.Groups["description"].ToString();
MAC = m.Groups["MAC"].ToString();

if (Regex.IsMatch(description, "vmware", RegexOptions.IgnoreCase))
continue;

Console.WriteLine(description);
Console.WriteLine(MAC);
}
In a DOS prompt, this will print:

SiS 900 PCI Fast Ethernet Adapter
00-0A-E6-AD-4B-B7
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Harry | last post by:
Hi there, does anyone know how I can build a regular expression e.g. for the string.search() function on runtime, depending on the content of variables? Should be something like this: var...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
3
by: James D. Marshall | last post by:
The issue at hand, I believe is my comprehension of using regular expression, specially to assist in replacing the expression with other text. using regular expression (\s*) my understanding is...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
3
by: LordHog | last post by:
Hello all, I am attempting to create a small scripting application to be used during testing. I extract the commands from the script file I was going to tokenize the each line as one of the...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
5
by: shawnmkramer | last post by:
Anyone every heard of the Regex.IsMatch and Regex.Match methods just hanging and eventually getting a message "Requested Service not found"? I have the following pattern: ^(?<OrgCity>(+)+),...
1
by: sunil | last post by:
Hi, Am writing one C program for one of my module and facing one problem with the regular expression functions provided by the library libgen.h in solaris. In this library we are having two...
1
by: Shawn B. | last post by:
Greetings, I'm using a custom WebBrowser control: http://www.codeproject.com/KB/miscctrl/csEXWB.aspx When I get the DocumentSource of a web page I browsed, and run a regular expression...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.