User Panel

Let’s Code with Python

Python is one of the most versatile and popular languages in use. We will go over setting up a basic environment so we can begin coding in python!

Setting up your environment:

If you have followed our tutorial on how to Install Kali Linux, then you already have a working environment!

If you have not, we recommend that you do! Linux is an incredibly lightweight and powerful operating system that is FREE and has plenty of open source software (software that is free and often developed by a community of developers). This means that almost all the tools on Linux are free to download and use.

With that being said… go install Kali since we also like the tools that comes with this distribution since we will use them to hack!

Now, if you are running linux, you SHOULD have python already installed on your OS, but we can still check…

$ python -verson    #this tells us which version of python is installed.

#on Kali, it will probably look like this: 

Python 2.7.14+  #this is a stable and sufficient version to learn python on, but you may opt to update to the latest python version; python 3.6.5: 

#to get the latest version of python, run this and specify the version in red:

$ apt-get install python 3.6.5

If you are on Mac OS or OSX, we recommend you take a look at MacPorts and consider using it to manage you python installs.

MacPorts is essentially a system which allows you to compile, install, and manage software. It functions similarly to apt-get on linux but is on Mac OS and works in terminal.

Similarly to how you would install python on linux, apt-get install python, using Mac Ports would look like:

$ sudo port install python27   # Installs python version 2.7 using MacPorts

So can you guess what the command for python version 3.5 would be??? Yup…

$ sudo port install python35   # Installs python version 3.5 using MacPorts

To install Mac Ports, please follow these instructions as they are the easiest to get up and running. We will discuss the reasons we may go with some of the other instructions on the Mac Ports website at a later time.

The easiest way to install MacPorts on a Mac is by downloading the pkg or dmg for High SierraSierraEl CapitanYosemite,MavericksMountain LionLionSnow LeopardLeopard or Tiger and running the system’s Installer by double-clicking on the pkg contained therein, following the on-screen instructions until completion.

This procedure will place a fully-functional and default MacPorts installation on your host system, ready for usage. If needed your shell configuration files will be adapted by the installer to include the necessary settings to run MacPorts and the programs it installs, but you may need to open a new shell for these changes to take effect.

The MacPorts “selfupdate” command will also be run for you by the installer to ensure you have our latest available release and the latest revisions to the “Portfiles” that contain the instructions employed in the building and installation of ports. After installation is done, it is recommended that you run this step manually on a regular basis to to keep your MacPorts system always current:

sudo port -v selfupdate

At this point you should be ready to enjoy MacPorts!

Type “man port” at the command line prompt and/or browse over to our Guide to find out more information about using MacPorts. Help is also available.

* The above section is directly from the MacPorts website.

Now to run python in your terminal, simply type “python” and you will be able to start coding python inside the terminal.

If you want to be able to run some code that you want to write inside a text file using a text editor of your choice, simply save the file and when you want to run the python code, run:

$ python myprogram.py   #this will run the program you wrote in the text file… (note that py is the python extension) and you can name your program anything you like…

On windows, we can first check to see if we already have python installed by simply typing “python” into the command prompt (cmd).

If we have it installed, we get something that looks like this:

Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

C:\Users\Username>cd C:\Python27

C:\Python27>python
Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win
32
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

If it turns out that we do not have python installed, we can install it by going to this link and finding the version of windows that you are currently running. If you do not know which version of Windows you are running, you can check this by going to Start Menu with the Windows logo, Click Start – RUN , and type “winver” and  finally press enter.

Now just install python!

Once it is complete, you can verify that the install was successful by typing python into the terminal and make sure you get something similar to the above code we would have gotten if it was installed in the first place.

Once it is complete, you can run python from the directory you installed it, this is usually the C:\ directory or C drive.

Note that if you want to learn how to be able to run python from ANY directory, which we highly recommend to our windows users, we suggest you do the following:

  • It would be nice to be able to run Python from any location without having to constantly reference the full installation path name. This can by done by adding the Python installation path to Windows’ PATH ENVIRONMENT VARIABLE
    *In Windows 7 and Windows 8, simply searching for “environment variables” will present the option to Edit the system environment variables. This will open the System Properties / Advanced tab
    *In Windows XP, right click on My Computer->Properties to open System Properties and click on the Advanced tab.
  1. On the System Properties / Advanced tab, click Environment Variables to open User Variables and System VariablesCreate a new System Variable named Variable name: PYTHON_HOME and Variable value: c:\Python27 (or whatever your installation path was)
  2. Find the system variable called Path and click EditAdd the following text to the end of the Variable value:;%PYTHON_HOME%\;%PYTHON_HOME%\Scripts\Verify a successful environment variable update by opening a new command prompt window (important!) and typing python from any location

NOTE that these same instructions are available WITH PICTURES at https://github.com/BurntSushi/nfldb/wiki/Python-&-pip-Windows-installation, but for now, you can skip the part of the directions that use pip.

And thats it! You can now run python on the three main operating systems and start learning to script with one of the most popular languages today!

Online Compilers?

If you really cannot wait to start learning and coding in python, or you don’t have your own computer at home, you can always opt to use online python compilers.  You can find many online python compilers like the one by Coding Ground.

Please note, however, that these compilers do not always work well and often are difficult to use, if they work at all, on mobile browsers and are certainly no substitute for real machine based compilers. We suggest that you get a copy of the Ubuntu, Linux, or Kali, and get a proper development environment set up. You will be grateful you did sooner rather than later.

If you would like some guidance on starting python on your own or want to get started early, we recommend checking out the Python Beginners Guide. If you have any questions, comments, or concerns, please leave it bellow. Happy coding!

OSS
info@oss.org
No Comments

Post A Comment