Solved

call ipconfig from Python, then return select results into list or dictionary

Posted on 2013-11-25
4
1,735 Views
Last Modified: 2013-11-26
I want to all a cmd.exe function such as ipconfig from the REPL and return results into a list to do something else with. Any ideas how to do this?
 Thanks folks!!
0
Comment
Question by:SaffronThePuppy
  • 3
4 Comments
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39676699
ipconfig > file.txt

Works in cmd and powershell.

Or, if you want to append, use >>

In powershell, $i = ipconfig will store the result of the command in $i

HTH,
Dan
0
 
LVL 34

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39676726
In Python, you can do

output = subprocess.check_output(['cmd.exe', '/c ipconfig'])

http://docs.python.org/2/library/subprocess.html

output will be a text variable, split it by endlines and you'll have your list.

HTH,
Dan
0
 

Author Closing Comment

by:SaffronThePuppy
ID: 39678799
Thank you, this answers the question. The actual command is a symcli command with complex output. It was calling the subprocess that I needed. Appreciated!
0
 
LVL 34

Expert Comment

by:Dan Craciun
ID: 39678928
Glad I could help. Thank you.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
This article will show, step by step, how to integrate R code into a R Sweave document
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now