Skip to content

Instantly share code, notes, and snippets.

View compor's full-sized avatar

Chris Vasiladiotis compor

  • University of Edinburgh
  • Edinburgh, Scotland, UK
  • 13:44 (UTC +01:00)
View GitHub Profile
@compor
compor / c_linux_tcpd_api_example.c
Created February 25, 2013 14:40
c linux tcpd api example
/*
simple usage of the tcpd/tcp wrapper API
a full-fledged program would probalby call hosts_access() upon accepting a new
connection and if denied it would close()
the established connection with FIN,ACK or most preferably RST
build with :
gcc -c tcpd_test.c
# capture SYN/ACK flagged packets
# tcp[13] is the byte location of TCP flags (URG,ACK,PSH,RST,SYN,FIN)
#
# mnemonic
#
# Unskilled 32
# Attackers 16
# Pester 8
# Real 4
# Security 2
@compor
compor / LineBreakButton.cpp
Created February 25, 2013 14:46
breaks up qpushbutton text in to multiple lines
// header
#include <qobject.h>
#include <qwidget.h>
#include <qpushbutton.h>
class LineBreakButton : public QPushButton {
Q_OBJECT
public:
@compor
compor / bash_sort_filezila_log.sh
Created February 25, 2013 14:47
sort filezilla server log entries by session id
#!/bin/bash
#
# entry example
#
# (1579051) 10/16/2009 0:02:13 AM - (not logged in) (192.168.1.11)> USER chris
#
# sort -k1n fzs-2009-10-16.log
# does not work properly because when the session id and timestamp are the same
# it goes on and tries to sort based on the message
@compor
compor / bash_iperf_mcast_source_sink.sh
Created February 25, 2013 14:49
multicast traffic source/sink with iperf
# multicast group 239.1.1.1 on port 4321
# multicast listener/sink with read buffer of 512 bytes
iperf -s -u -B 239.1.1.1 -i 1 -l 512 -p 4321
# multicast transmitter/source with write buffer of 512 bytes
# fill up bandwidth of 80Kb/s
@compor
compor / bash_check_ipv4_validity.sh
Created February 25, 2013 14:50
check ipv4 validity
# the argument must in a dot decimal ipv4 format
function is_valid_ipv4() {
if [ -z "$1" ]; then
return 0;
fi
IFS="."
local isvalid=1
local bytectr=0
@compor
compor / bash_openssl_pkcs12_envelope.sh
Created February 25, 2013 15:01
create pkcs12 cert envelope with openssl
# mycert.crt - certificate file
# mykey.key - private key file
openssl pkcs12 -export -in mycert.crt -inkey mykey.key -out env.p12 -password stdin
@compor
compor / bash_calc_elapsed_time_log_record.sh
Created February 25, 2013 15:03
elapsed time between two log records
#!/bin/bash
#
# parses the time (in seconds) that elapsed between 2 consecutive entries
# each matching to pattern1 and pattern2.
# date format : [DDD] [MMM] [dd] [hh]:[mm]:[ss] [YYYY]
# example : Tue May 12 06:49:44 2009
#
# substitute the patterns at will
#
@compor
compor / bash_patch_between_files.sh
Created February 25, 2013 15:09
create and apply a patch between files in two directories
# produces a patch between the files in the 2 dirs
# -c : special context for output
# -r : directory recursively
# -B : ignore blanks
diff -crB before_dir after_dir > foo.patch
# if you want to patch before_dir now
@compor
compor / bash_iptables_ping_limit_rate.sh
Created February 25, 2013 15:12
limit rate pings with iptables
iptables -A INPUT -p icmp -m limit --limit 39.6/m --limit-burst 1 -j DROP
# it will cause 2 out of 3 icmp replies to fail when executing a ping like
# ping -c 3 -i 1 -w 3 10.10.10.10
#
# we needed 1 out of 3 successful ping replies in, so that's 2/3 ~= 0.67 replies per second
# since we cannot use less than 0 values, we up the scale to the minute, so
# 0.67 * 60 = 39.6 replies in 1 minute :-)