Useful Libraries
Executing commands
subprocess
import subprocess
# Executing the "ls -la" command:
s = subprocess.Popen(["ls", "-la"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# unpacking the stdout and stderr
data, err = s.communicate()
# printing the data to stdout
print(data)
os.system
import os
username = 'root'
ip_address = '10.10.10.161'
# Using os.system to ssh to a remote box
shell = "ssh -i " + '$HOME/.ssh/id_rsa ' + username+"@"+ip_address
os.system(shell)
Fancy Printing and Color
tabulate
pip3 install tabulate
#!/usr/bin/env python3
from tabulate import tabulate
table = [[‘bacon’, 10], [‘eggs’, 12], [‘pancakes’, 8]]
Headers = [‘items’, ‘qty’]
print (tabulate(table, headers, tablefmt=‘fancy_grid’))
╒══════════╤═══════╕
│ items │ qty │
╞══════════╪═══════╡
│ bacon │ 10 │
├──────────┼───────┤
│ eggs │ 12 │
├──────────┼───────┤
│ pancakes │ 8│
╘══════════╧═══════╛
# Example: tabulate(table, stralign=“center”, tablefmt=“fancy_grid”, headers=“firstrow”)
termcolor
from termcolor import colored
print colored('*********** Webmin 1.910 Exploit By roughiz*********', "blue")
print colored('****************************************************', "blue")
print colored('****************************************************', "blue")
print colored('****************************************************', "blue")
print colored('*********** Retrieve Cookies sid *******************', "blue")
Graphing and Plotting Data
matplotlib
# To install the library
pip3 install matplotlib
# The code
import matplotlib.pyplot as plt
year = [1950, 1960, 1970, 1980]
pop = [2.519, 3.692, 5.263, 6.972]
plt.plot(year, pop)
plt.xlabel('Year')
plt.ylabel('Population')
plt.title('World Population Projection')
#You can also do the following to change the ticks
#This will make the y axis show in "B" Billions
plt.yticks([0,2,4,6,8,10], ['0', '2B','4B','6B','8B','10B'])
plt.show()
Last updated