#!/bin/bash cookies=./cookies.txt sessionID_url='https://lk.megafon.ru/login/' login_url='https://lk.megafon.ru/login/dologin/' logout_url='https://lk.megafon.ru/logout/' useragent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0" balance="" i=0 attempts=5 timeout=20 username='phone_number' # 10- 8- 7- password='password' # while [[ "$balance" == "" && "$i" -le "$attempts" ]]; do let "i+=1" # ---------- CSRF / SessionID --------------- CSRF=`curl -A "$useragent" -c "$cookies" "$sessionID_url" | grep "CSRF_PARAM" | grep -o -E "([Aa]|[0-9])\S+-\S+-\S+-\S+-\S+([Aa]|[0-9])"` userdata="CSRF=$CSRF&j_username=$username&j_password=$password" balance=`curl -A "$useragent" -b "$cookies" -dump -L -X POST "$login_url" -d "$userdata" | grep -E -o "\s\S+\s[0-9]{1,},[0-9]{1,}" | grep -E -o "[0-9]{1,},[0-9]{1,}"` if [ "$balance" == "" ]; then sleep "$timeout" fi done if [ "$balance" != "" ]; then echo " = $balance ." else echo " , ." fi # ------ LOGOUT --------------------------------- sleep 5 curl -b "$cookies" -L "$logout_url" > /dev/null 2>&1 if [ -f "$cookies" ]; then rm "$cookies" fi exit 0
#!/bin/bash page_dump=/usr/tmp/dump url='http://user.moscow.megafon.ru/' useragent="Mozilla/5.0 (Windows NT 6.1; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0" balance="" traffic="" phone="" balance_deadline="100" traffic_deadline="1" # -------- sendmail function ------------- function sendalert () { FROM_EMAIL_ADDRESS="my@mail.ru" EMAIL_USER="userlogin" EMAIL_ACCOUNT_PASSWORD="password" TO_EMAIL_ADDRESS="mailto@domain.ru" echo "$2" | mailx -s "$1" \ -S smtp-use-starttls \ -S ssl-verify=ignore \ -S smtp-auth=login \ -S smtp=smtp://smtp.yandex.ru \ -S smtp-auth-user="$EMAIL_USER" \ -S smtp-auth-password="$EMAIL_ACCOUNT_PASSWORD" \ -S from="$FROM_EMAIL_ADDRESS" \ "$TO_EMAIL_ADDRESS" } curl -A "$useragent" -dump "$url" >"$page_dump" balance=`cat "$page_dump" | grep -E -o 'balance(\S+\s)*' | grep -E -o '[0-9]{1,},[0-9]{1,}'` traffic=`cat "$page_dump" | grep -E -o 'traffic-by\S+' | grep -E -o '[0-9]{1,}(,[0-9]{1,})*'` phone=`cat "$page_dump" | grep -E -o 'phone.*+7' | grep -E -o '\([0-9]{3}\)\s[0-9]{3}(-[0-9]{2}){2}'` bal_test=`echo "$balance" | sed -e 's/,.*//'` traff_test=`echo "$traffic" | sed -e 's/,.*//'` if [ "$traff_test" -lt "$traffic_deadline" ]; then sendalert " $phone" " - $phone - $traffic " fi if [ "$bal_test" -lt "$balance_deadline" ]; then sendalert " $phone" " - $phone - $balance ." fi if [ -f "$page_dump" ]; then rm "$page_dump" fi exit 0
# -------- sendmail function ------------- function sendalert () { FROM_EMAIL_ADDRESS="my@mail.ru" EMAIL_USER="userlogin" SMTP_SERVER="smtp.yandex.ru" EMAIL_ACCOUNT_PASSWORD="password" TO_EMAIL_ADDRESS="mailto@domain.ru" sendEmail -f "$FROM_EMAIL_ADDRESS" \ -t "$TO_EMAIL_ADDRESS" \ -s "$SMTP_SERVER" \ -o message-charset=utf8 \ -xu "$EMAIL_USER" \ -xp "$EMAIL_ACCOUNT_PASSWORD" \ -u "$1" \ -m "$2" }
Source: https://habr.com/ru/post/357610/
All Articles