I am trying to write a Python script in Windows 7 that reads the output of a command ipconfig /displaydnsand tries to get some values โโfrom the output.
The result ipconfig /displaydns"looks something like this:
Windows IP Configuration
9.a.c.e.x-0.19-430f5091.531.1518.1b8d.2f4a.210.0.k1m2t5a3245k242qmfp75spjkv.avts.
Record Name . . . . . : 9.a.c.e.x-0.19-430f5091.531.1518.1b8d.2f4a.210.0.k1m2t5a3245k242qmfp75spjkv.avts.
Record Type . . . . . : 1
Time To Live . . . . : 294
Data Length . . . . . : 4
Section . . . . . . . : Answer
A (Host) Record . . . : 127.0.0.16
I take this output and save it in a variable as shown below,
output = subprocess.check_output("ipconfig /displaydns", shell=True)
When I print "output", I get the following
b'\r\nWindows IP Configuration\r\n\r\n 9.a.c.e.x-0.19-430f5091.531.1518.1b8d.2f4a.210.0.k1m2t5a3245k242qmfp75spjkv.avts.\r\n
From this conclusion, I am interested in the values โโfor A (Host) Recordand Record Name, which are 127.0.0.16and 9.a.c.e.x-0.19-430f5091.531.1518.1b8d.2f4a.210.0.k1m2t5a3245k242qmfp75spjkv.avts.respectively.
How can I do this in Python?
source
share