Thursday, December 1, 2011

Monitoring my network traffic

Today I wrote this simple script to monitor my network traffic. I release this script under GPLv3

Enjoy

#!/bin/sh
# monitor-traffic.sh - Monitor network traffic excluding common requests
# Andres Hernandez - Tonejito

TCPDUMP=/usr/sbin/tcpdump
IP=/sbin/ip
DEV=en1
ADDR=`$IP addr show dev $DEV | grep 'inet ' | cut -d ' ' -f 6 | cut -d '/' -f 1`

$TCPDUMP -ni $DEV "host $ADDR and port not (67 or 68 or 80 or 443 or 1863 or 5222 or 587 or 993 or 995)"

--
= ^ . ^ =

Tuesday, November 15, 2011

zerofree - Zero out space on a virtual machine

Today, I had to shrink a virtual machine size for deployment.

I like the zerofree utility that clears the unallocated blocks in a ext2/ext3/ext4 filesystem.

Take a look at the code snipplet

First go to single user

# init 1

Then do the magic

# for i in `mount | grep sda | grep ext | cut -b 9` ; do mount -o remount,ro /dev/sda$i && zerofree -v /dev/sda$i && mount -o remount,rw /dev/sda$i ; done ;

And here is a sample on a VirtualBox VM



--
= ^ . ^ =

Tuesday, September 27, 2011

Sep 27th 2011 - Transfer data between virtual machine and host without network

Today I needed to transfer data between a virtual machine and the host.

The main problem was the lack of networking support in MINIX v3.1.0 (the virtual machine) so I could not scp or ftp anything between the systems.

I came to rescue the day with the idea of a special sneakernet between the virtual machine and the host.

On the host

  • Create the floppy image on the host.

    % dd if=/dev/zero of=floppy.img bs=1024 count=1440


  • Attach the floppy image to the virtual machine.

    The process depends on the virtualization software so is left as exercise to the reader.


On the virtual machine

  • cd to the data (let's call it payload, shall we?.

    $ cd /home/tonejito/payload


  • tar the relevant files into the floppy device (/dev/fd0)

    $ tar cvvf /dev/fd0 file file file ...


On the host

  • Detach the floppy image from the virtual machine

    Another exercise left to the reader

  • Extract the files
    % tar xvvf floppy.img

  • List the contents

    % ls
    floppy.img file file file



That's all

Sunday, September 18, 2011

ssh write failed: broken pipe

I hate when this kind of things so I surfed the net looking for an answer [1], the cause of the problem was the inactivity in the ssh session, so a keep-alive must be implemented somewhere.

It turned out in the manpages of ssh_config and sshd_config there were a couple keep alive settings:

/etc/ssh/ssh_config
ServerAliveInterval 30
TCPKeepAlive yes

/etc/ssh/sshd_config
ClientAliveInterval 30
TCPKeepAlive yes

Server/Client Alive interval are protocol-specific settings, and TCP is a connection-specific setting.

[1] https://bbs.archlinux.org/viewtopic.php?id=97003

[2] LIDSOL website

init 0 ;

Wednesday, August 31, 2011

StackOverflow.java

% cat StackOverflow.java
class StackOverflow
{
public static void main(String[] args)
{
StackOverflow.main(args);
}
}

% javac StackOverflow.java && java StackOverflow 2>&1 | vim -
1:Exception in thread "main" java.lang.StackOverflowError
2: at StackOverflow.main(StackOverflow.java:5)
3: at StackOverflow.main(StackOverflow.java:5)
...
1025: at StackOverflow.main(StackOverflow.java:5)

Thursday, August 11, 2011

make me a sandwich

% cat Makefile
me: a

a: sandwich

sandwich:
% make me a sandwich
make: `me' is up to date.
make: `a' is up to date.
make: Nothing to be done for `sandwich'.

--
  = ^ . ^ =

Tuesday, August 9, 2011

random.c

% cat random.c
#include
#include
#include
#include

int main(int argc,char* argv[])
{
unsigned int i=0;

initstate(random(),(char*)argv,argc);

for (i=0;i
fprintf(stderr,"%d\n",random());

return EXIT_SUCCESS ;
}

% cat Makefile
CC=cc
FLAGS=-ansi -static -Wall --pedantic

random: random.c
${CC} ${FLAGS} -o random random.c

% make
% ./random 1>random.out 2>random.err
...