- Learning Penetration Testing with Python
- Christopher Duffy
- 306字
- 2021-07-09 21:52:54
Environmental variables and PATH
These variables are important for executing scripts written in Python, not for writing them. If they are not configured, the location of the Python binary has to be referenced by its fully qualified path location. As an example, here is the execution of a Python script without the environmental variable being declared in Windows:
C:\Python27\python wargames_print.py
The following is the equivalent in Linux or Unix if the reference to the proper interpreter is not listed at the top of the script and the file is in your current directory:
/usr/bin/python ./wargames_print.py
In Windows, if the environmental variable is set, you can simply execute the script by typing python
and the script name. In Linux and Unix, we add a line at the top of the script to make it more portable. A benefit to us (penetration testers) is that this makes the script useful on many different types of systems, including Windows. This line is ignored by the Windows operating system natively, as it is treated as a comment. The following referenced line should be included at the top of all Python scripts:
#!/usr/bin/env python
This line lets the operating system determine the correct interpreter to run based on what is set in the PATH
environmental variable. In many script examples on the Internet, you may see a direct reference to an interpreter, such as /usr/bin/python
. This not considered good practice as it makes the code less portable and more prone to errors with potential system changes.
Tip
Setting up and dealing with PATH
and environmental variables will be different for each operating system. Refer to https://docs.python.org/2/using/windows.html#excursus-setting-environment-variables for Windows. For Unix and Linux platforms, the details can be found at https://docs.python.org/2/using/unix.html#python-related-paths-and-files. Additionally, if you need to create specialty environmental variables for a specific tool someday, you can find the details at https://docs.python.org/2/using/cmdline.html.
- Software Defined Networking with OpenFlow
- Visual C++串口通信開發(fā)入門與編程實(shí)踐
- Getting Started with ResearchKit
- Android Development with Kotlin
- Groovy for Domain:specific Languages(Second Edition)
- Java Web基礎(chǔ)與實(shí)例教程
- Learn React with TypeScript 3
- 軟件測(cè)試技術(shù)指南
- 區(qū)塊鏈底層設(shè)計(jì)Java實(shí)戰(zhàn)
- 領(lǐng)域驅(qū)動(dòng)設(shè)計(jì):軟件核心復(fù)雜性應(yīng)對(duì)之道(修訂版)
- 時(shí)空數(shù)據(jù)建模及其應(yīng)用
- Java程序設(shè)計(jì)教程
- Clojure High Performance Programming(Second Edition)
- Java程序設(shè)計(jì)實(shí)用教程(第2版)
- WordPress Search Engine Optimization(Second Edition)