Tag: Python

scapy packet dump to packet

First you need to have scapy installed. And if you don’t know about scapy, then

Scapy is a powerful interactive packet manipulation program. It is able to forge or decode packets of a wide number of protocols, send them on the wire, capture them, match requests and replies, and much more. It can easily handle most classical tasks like scanning, tracerouting, probing, unit tests, attacks or network discovery (it can replace hping, 85% of nmap, arpspoof, arp-sk, arping, tcpdump, tethereal, p0f, etc.). It also performs very well at a lot of other specific tasks that most other tools can’t handle, like sending invalid frames, injecting your own 802.11 frames, combining technics (VLAN hopping+ARP cache poisoning, VOIP decoding on WEP encrypted channel, …), etc

So, just install scapy

dnf install PyX scapy

Once done, start scapy so that you can capture and see the packet in pdf.

a=sniff(count=1)
a.pdfdump

Get disk usage for all the containers with python script

With my increasing love for python, here is my attempt to get the disk usage of all the containers on some host. Well, since the requirements vary for everyone, so this script is far from complete.

import docker
import json

# We will connect to 192.168.122.1 for docker daemon. If that is not the case,
# then change the below.

client = docker.DockerClient(base_url="tcp://192.168.122.1:4243")

# Get list of all containers.
cls=client.containers.list()
stats={}

# And now we will iterate over that list to get stats for all the containers.
for val in cls:
    print (val.name)
    stats[val.name] = val.stats(stream=False)
    # Get the disk usage for root and /tmp from containers with docker.exec
    stats[val.name]['df-root'] = ( str(val.exec_run(r'df -kh --output="size,used,avail,pcent" /', stream=False).splitlines()[1]).replace("'","").split()[1:] )
    stats[val.name]['df-tmp'] = ( str((val.exec_run(r'df -kh --output="size,used,avail,pcent" /tmp ', stream=False).splitlines()[1:]+[''])[0]).replace("'","").split()[1:] )

# Now if you want, we have dict of all the data and we can process the
# way we like it, for example create a html table for disk usage only.
print ('<table>')
for st in stats:
    print ('<tr>')
    print ("<td>Root-%s</td>"%(st))
    for i in stats[st]['df-root']:
        print ('<td>%s</td>'%(i) )
    print ('</tr>')
    print ('<tr>')
    print ("<td>tmp-%s</td>"%(st))
    for i in stats[st]['df-tmp']:
        print ('<td>%s</td>'%(i) )
    print ('</tr>')

print ('</table>')

supernova – manage multiple openstack environment

supernova is an easy to use tool that helps manage multiple openstack environments.

Details –

Name        : supernova
Arch        : noarch
Epoch       : 0
Version     : 2.2.0
Release     : 2.fc24
Size        : 62 k
Repo        : @System
From repo   : fedora
Summary     : Use novaclient with multiple OpenStack nova environments the easy way
URL         : https://github.com/major/supernova
License     : ASL 2.0
Description : supernova manages multiple nova environments without sourcing
: novarc files or mucking with environment variables.

To get started, start with installing supernova with

dnf install supernova

and after that you need to create the configuration file, typically “~/.supernova” with content such as:


1
2
3
4
5
6
7
8
9
10
[production]
OS_AUTH_URL=https://identity.api.rackspacecloud.com/v2.0/
OS_AUTH_SYSTEM=rackspace
OS_COMPUTE_API_VERSION=1.1
NOVA_RAX_AUTH=1
OS_REGION_NAME=<a class="zem_slink" title="Deutsche Flugzeug-Werke" href="http://en.wikipedia.org/wiki/Deutsche_Flugzeug-Werke" target="_blank" rel="wikipedia">DFW</a>
NOVA_SERVICE_NAME=cloudServersOpenStack
OS_PASSWORD=my_password
OS_USERNAME=my_username
OS_TENANT_NAME=my_tenant_name

1
2
3
4
5
6
7
8
9
10
[development]
OS_AUTH_URL=https://identity.api.rackspacecloud.com/v2.0/
OS_AUTH_SYSTEM=rackspace
OS_COMPUTE_API_VERSION=1.1
NOVA_RAX_AUTH=1
OS_REGION_NAME=DFW
NOVA_SERVICE_NAME=cloudServersOpenStack
OS_PASSWORD=my_password-devel
OS_USERNAME=my_username-devel
OS_TENANT_NAME=my_tenant_name

1
You can check out the configuration section of <a href="http://supernova.readthedocs.io/en/latest/gettingstarted/">Getting started</a> page.

And once you have created the configuration file, it is very simple. Some example commands

supernova [enviromment_name[,enviromment_name]...] [commands]

Examples

supernova prod list
supernova prod image-list
supernova prod flavor-list
supernova prod boot --image image_uuid --flavor flavor_id myserver.example.com