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