借助curl实现自动化登陆校园网Dr.com

#!/bin/sh
# This script intends to make logging into Dr.com easy.
# However, Dr.com has different implementations in different occasions.
# Tweak this script to cater to your taste!
login_page="http://192.168.255.1/a70.htm"
logout_page="http://192.168.255.1/F.htm"
name="your_loging_name"
pass="your_password"

help() {
  echo "Usage: ./campus-link <up|down>"
}

case $1 in 
  u*)
    ret=`curl -s -S -X POST --data "DDDDD=$name&upass=$pass&R1=0&R3=0&R6=0¶=00&0MKKey=123456" $login_page | grep -a Dr.COMWebLoginID_3.htm | wc -c`
    if [ $ret -gt 0 ] ; then
      echo "campus-link logged in successfully."
    else
      echo "Returned data abnormal. Check your login."
    fi
    ;;
  d*)
    ret=`curl -s -S $logout_page | grep -a Dr.COMWebLoginID_2.htm | wc -c`
    if [ $ret -gt 0 ] ; then
      echo "campus-link logged out successfully."
    else
      echo "Returned data abnormal. Check your logout."
    fi
    ;;
  *)
    help
    ;;
esac