RE - Parsing ipconfig /all output - question

  • Follow


I'm trying to get the first MAC address from the ipconfig /all output.
Unfortunately you can't just search for Physical Address because the
name is only valid in the English Windows version.

Here a test which isn't working:

import subprocess
import re
p = subprocess.Popen('ipconfig /all', shell = True, stdout
=subprocess.PIPE)
p.wait()
rawtxt = p.stdout.read()
print rawtxt
p = re.findall(r'(%X%X-){5}%X%X',rawtxt)
print p

Any ideas?
0
Reply joblack 6/7/2010 3:47:31 AM

On Sun, Jun 6, 2010 at 10:47 PM, joblack <johannes.black@gmail.com> wrote:
> I'm trying to get the first MAC address from the ipconfig /all output.
> Unfortunately you can't just search for Physical Address because the
> name is only valid in the English Windows version.

> Any ideas?

(accidentally sent original to Johannes only)

This filters out all the false positives on my machine (Windows 7 x64 English):

import subprocess
import re
p = subprocess.Popen('ipconfig /all', shell = True, stdout=subprocess.PIPE)
p.wait()
rawtxt = p.stdout.read()
print rawtxt

p = re.findall(r'\s([0-9A-F-]{17})\s',rawtxt)
print p

Tim
0
Reply Tim 6/7/2010 4:38:16 AM


Great - seems to work =) ...

0
Reply joblack 6/7/2010 4:43:45 AM

2 Replies
759 Views

(page loaded in 0.001 seconds)

Similiar Articles:













7/24/2012 6:51:58 AM


Reply: