HIT校园网登录

作者: zsh2517 分类: 未分类 发布时间: 2020-08-29 20:59

Linux Shell 文件

windows 请通过 git bash 或者其他兼容 Linux Shell 的程序

例如 git bash

C:\Program Files\Git\git-bash.exe -i C:\users\zsh2517\desktop\login.sh
uid=""
pwd=""

function get_json_value()
{
  local json=$1
  local key=$2

  if [[ -z "$3" ]]; then
    local num=1
  else
    local num=$3
  fi

  local value=$(echo "${json}" | awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'${key}'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p)

  echo ${value}
}
# https://www.tomczhen.com/2017/10/15/parsing-json-with-shell-script/

data=`curl http://baidu.com -s`
substr="eportal"
result=$(echo $data | grep "${substr}")
if [[ "$result" != "" ]]
then
    res=`echo $result | grep -oE "\?.*'"`
    # echo ${res:1:${#res}-2}
    arg=${res:1:${#res}-2}
    status=`curl -s -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' \
    "http://202.118.253.94:8080/eportal/InterFace.do?method=login" \
    --data-urlencode "userId="$uid \
    --data-urlencode "password="$pwd \
    --data-urlencode "service=" \
    --data-urlencode "queryString="$arg \
    --data-urlencode "operatorPwd=" \
    --data-urlencode "operatorUserId=" \
    --data-urlencode "validcode=" \
    --data-urlencode "passwordEncrypt=false"`
    # echo $status
    substr="success"
    temp=$(echo $status | grep "${substr}")

    if [[ "$temp" != "" ]]
    then
        echo "Login Success"
    else
        echo "Login Failed, REASON: ["`get_json_value $status message`"]"
    fi
else
    echo "Have logged in"
fi
echo "Enter退出"
read anykey

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

电子邮件地址不会被公开。 必填项已用*标注

标签云