View xml files like a pro

Viewing XML files can be daunting with tracking mentally where the tag starts and where it ends. So, I ended up with the following alias to help me view xml files

xmllint --format - | pygmentize -f 16m -O style=native -g

Add files to dropbox with single curl command

I have been thinking of posting this for sometime now. This is very useful, when you are working on a different Linux box and want to upload a file to dropbox.

 

So, before you run this command, you need to create your auth token in Dropbox developer API page. Once that is done, need to change the 2 parameters in command below. Export your Access token and run the below command.

Here is the command:

tar cvzf /tmp/backup.tgz <folder of your choice>
curl -X POST https://content.dropboxapi.com/2/files/upload \
    --header "Authorization: Bearer $OAUTH_ACCESS_TOKEN" \
    --header "Dropbox-API-Arg: {\"path\": \"/<dropbox path>/$(hostname -s)/$NOW.tgz\"}" \
    --header "Content-Type: application/octet-stream" \
    --data-binary @/tmp/backup.tgz

Split pcap to multiple files based on number of packets

Here is a script that can use tshark to split a large pcap to multiple small pcaps

 

inpcap="test.pcap"

max=$(tshark  -r $inpcap -n -T fields -e frame.number|tail -1)

# This is the number of packets in each split pcap
c=1

# Save all new pcaps to out, if it does not exist, create it.
[[ ! -d out ]] && mkdir out

for i in $(seq 1 $max $c)
do
        tshark  -r $inpcap  -n -c $c "frame.number==$i" -w out/$i.pcap
        #Do other stuff, if required
        read -p "Send the next packet? "
done

A very simple 3-4 line script that has saved my day so may times.

 

Edit: I found a nice tcpdump cheatsheet https://comparite.ch/tcpdumpcs