终端命令行下一些有趣的函数

0x00 Biubiubiu~

OS : Mac OSX
Shell : zsh
Plugin : oh-my-zsh

0x01 IP Helper

ip2hex () {
    local a b c d ip=$@
    IFS=. read -r a b c d <<< "$ip"
    printf '0x%x\n' "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))"
}
hex2ip () {
    local ip dec=$@
    desc=$(($desc))
        for e in {3..0}
    do
        ((octet = dec / (256 ** e) ))
            ((dec -= octet * 256 ** e))
            ip+=$delim$octet
            delim=.
            done
            printf '%s\n' "$ip"
}
ip2dec () {
    local a b c d ip=$@
        IFS=. read -r a b c d <<< "$ip"
        printf '%d\n' "$((a * 256 ** 3 + b * 256 ** 2 + c * 256 + d))"
}
dec2ip () {
    local ip dec=$@
        for e in {3..0}
    do
        ((octet = dec / (256 ** e) ))
            ((dec -= octet * 256 ** e))
            ip+=$delim$octet
            delim=.
            done
            printf '%s\n' "$ip"
}

0x02 Socks5 Proxy

function ssup() {
    export ALL_PROXY=socks5://127.0.0.1:1080
}

function ssdown() {
    unset ALL_PROXY
}

# show my ip
function myip(){
    curl myip.ipip.net
}

0x03 String Helper

function str2hex() {
    printf "0x"
    I=0
    while [ $I -lt ${#1} ];
    do
    printf "%x" "'"${1:$I:1}
    let "I += 1"
    done
    echo ""
}

function hex2str () {
    // TODO
}

0x04 Python Helper

function clearpyc(){
    echo "list *.pyc"
    find `pwd` -name "*.pyc" -o -name "__pycache__"
    echo "Deleting *.pyc ..."
    find `pwd` -name "*.pyc" -delete
    echo "Deleting __pycache__ ..."
    find `pwd` -type d -name "__pycache__" -exec rm -rf {} \;
    echo "Successfully"
}
alias clspyc='clearpyc'