Q:

How to list all the IP addresses defined on a Windows system with python?

On a Windows7 machine I have added some virtual IP addresses, so the output of ipconfig is as follows:
Windows IP Configuration

Ethernet adapter LAN-Verbindung:

   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::2d27:f07a:a617:b01e%11
   IPv4 Address. . . . . . . . . . . : 172.16.5.23
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   IPv4 Address. . . . . . . . . . . : 172.16.5.161
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   IPv4 Address. . . . . . . . . . . : 172.16.5.162
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   IPv4 Address. . . . . . . . . . . : 172.16.5.163
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 172.16.5.1

Ethernet adapter VirtualBox Host-Only Network:

----

With standard-python, using only standard libraries, how can I get a list of all thise IPv4 addresses, i.e. I want to have some python code returning the following information:
172.16.5.23
172.16.5.161
172.16.5.162
172.16.5.163

How can I do that with python? Ideally in one line?

A:

import subprocess
import re
proc = subprocess.check_output("ipconfig" )
print "\n".join(re.findall(r"(?<=IPv4 Address. . . . . . . . . . . : )(\d+\.\d+\.\d+\.\d+)",proc))

An example:
s = """
Ethernet adapter LAN-Verbindung:
   Connection-specific DNS Suffix  . :
   Link-local IPv6 Address . . . . . : fe80::2d27:f07a:a617:b01e%11
   IPv4 Address. . . . . . . . . . . : 172.16.5.23
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   IPv4 Address. . . . . . . . . . . : 172.16.5.161
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   IPv4 Address. . . . . . . . . . . : 172.16.5.162
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   IPv4 Address. . . . . . . . . . . : 172.16.5.163
   Subnet Mask . . . . . . . . . . . : 255.255.255.0
   Default Gateway . . . . . . . . . : 172.16.5.1
   """
In [13]: print "\n".join(re.findall(r"(?<=IPv4 Address. . . . . . . . . . . : )(\d+\.\d+\.\d+\.\d+)",s))
172.16.5.23
172.16.5.161
172.16.5.162
172.16.5.163

