# Useful Libraries

## Executing commands

### subprocess

```python
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

```python
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

```python
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

```python
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

```python
# 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()
```

![](https://3391461163-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-SeUOaaky_0dmtDTFu%2F-M1Ck4y9DNgemckeRrvM%2F-M1ClxY9KvNqYoAp5f1P%2Fimage.png?alt=media\&token=ce5ba1ef-5bb7-4cf4-9b29-25a052af038e)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://squid22.gitbook.io/notes/python/useful-libraries.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
