Fix weird flux menu

Some distro’s just add all the items under single menu and thus the menu itself becomes unusable because of the number of items in the submenu and this I did not like and hence ceated this simply python script to fix that. For using the script, back up you “menu” file, redirect the output of this script to ‘menu’ file again.

 

#!/bin/python

F = open("~/.fluxbox/menu", "r")
count=0
mkc=1
started=0

for line in F:
    print line.rstrip()

    if '[submenu]' in line.lower() and started == 1:
        print '[end]'

    if '[end]'  in line.lower():
        count=0
        mkc=1
        if started > 0:
             started=0
             # print "Count is {}".format(count)
             # print "Started is {}".format(started)
             print '[end]'
    if '[exec]'  in line.lower():
        if count > 15 :
            if started > 0:
                started=0
                print '[end]'
                # print "Count is {}".format(count)
                # print "Started is {}".format(started)
            print '[submenu] ({})'.format(mkc)
            started=1
            mkc+=1
            count=0
        # print count
        count+=1

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>')