fredag 26 november 2010

kontrollsiffra personnummer oneliner in python

def pnr(nr,d=2,c=0,i=0): return (i==9) and 10-(c%10) or pnr(str(nr),3-d,c+(d*int(nr[i]))%10+(d*int(nr[i]))/10,i+1)

def pnr(p):
    a,p=[0,2,4,6,8,1,3,5,7,9],[int(i) for i in p]
    return 10-(a[p[0]]+p[1]+a[p[2]]+p[3]+a[p[4]]+p[5]+a[p[6]]+p[7]+a[p[8]])%10

print "sista siffran = %d" % pnr("6408233234"[:-1])

torsdag 25 november 2010

Setup IPSec between two hosts

# based on

key() ( bits=$1; dd if=/dev/random count=$((bits/8)) bs=1| xxd -ps )


cat > setkey.conf <
#!/usr/sbin/setkey -f

# Configuration for $host1

# Flush the SAD and SPD

# set the authentication header
# AH SAs using 128 bit long keys
add $host2 $host1 ah 0x200 -A hmac-md5  0x$(key 128);
add $host1 $host2 ah 0x300 -A hmac-md5  0x$(key 128);

# ESP SAs using 192 bit long keys (168 + 24 parity)
add $host2 $host1 esp 0x201 -E 3des-cbc  0x$(key 192);
add $host1 $host2 esp 0x301 -E 3des-cbc  0x$(key 192);

# Security policies
spdadd $host2 $host1 any -P out ipsec

spdadd $host1 $host2 any -P in ipsec


sudo setkey -f setkey.conf

# copy setkey.conf to the other computer (host2),
# and on the other computer swap the '-P in' and '-P out'
# in the spdadd and run the sudo setkey -f setkey.conf
# WARNING! You will not be able to contact the other
# computer if only one of them has enabled the IPSec rules
# with setkey.

måndag 1 november 2010

multiple users on one screen session

I got this info from here.

Suppose larsr and bill have accounts on a machine stella.
Thanks to 'screen' they can easily share a terminal window.

both log in to stella (for instace with ssh).

larsr starts screen

  • screen

and enables multiuser mode

  • CTRL-a :multiuser on

and permit bill to connect

  • CTRL-a :acladd bill

Now bill can connect to the screen by typing

  • screen -x larsr/

Note the '/'. If larsr has many screens, the screen id is entered after the '/'.