Skip to content

Instantly share code, notes, and snippets.

@pourmand1376
Last active March 29, 2025 08:03
Show Gist options
  • Save pourmand1376/965625a56c9e8ba4a82cd6f7dd98ed80 to your computer and use it in GitHub Desktop.
Save pourmand1376/965625a56c9e8ba4a82cd6f7dd98ed80 to your computer and use it in GitHub Desktop.
Sharif Login
function sharif_login
{
curl -d "username=$1&password=$2" -X POST "https://net2.sharif.edu/login" > /dev/null
curl -s https://net2.sharif.edu/status | grep -o '<td>.*</td>'
sleep 1s # To See login status
}
function sharif_ip
{
# from ping net2.sharif.edu
# this is written since sometimes DNS server doesn't work!
curl -d "username=$1&password=$2" -X POST -k "https://172.17.1.214/login" > /dev/null
curl -sk https://172.17.1.214/status | grep -o '<td>.*</td>'
sleep 1s # To See login status
}
function sharif_logout
{
curl -d "username=test&password=test" -X POST "https://net2.sharif.edu/logout"
sleep 1s
}
sharif_login1() {
sharif_login "YourUsername" "YourPassword"
}
sharif_ip1() {
sharif_ip "YourUsername" "YourPassword"
}
alias 1="sharif_login1 && exit"
alias ۱="1"
@SaeedForoutan
Copy link

SaeedForoutan commented Feb 23, 2024

Thanks for this beneficial code! I found it really helpful. I have a suggestion to enhance it further – consider putting the sharif_login1 directly in an alias and removing the exit at the end. Here's a simplified version:

alias 1="sharif_login YourUsername Yourpassword"

@pourmand1376
Copy link
Author

Edited Script via Claude.ai.

#!/bin/bash

# Function to URL encode strings
urlencode() {
    local string="${1}"
    local strlen=${#string}
    local encoded=""
    local pos c o

    for (( pos=0 ; pos<strlen ; pos++ )); do
        c=${string:$pos:1}
        case "$c" in
            [-_.~a-zA-Z0-9] ) o="${c}" ;;
            * )               printf -v o '%%%02x' "'$c"
        esac
        encoded+="${o}"
    done
    echo "${encoded}"
}

# Function for Sharif login
sharif_login() {
    if [ $# -ne 2 ]; then
        echo "Usage: sharif_login <username> <password>"
        return 1
    fi
    local username=$(urlencode "$1")
    local password=$(urlencode "$2")
    
    if curl -d "username=${username}&password=${password}" -X POST "https://net2.sharif.edu/login" > /dev/null 2>&1; then
        curl -s https://net2.sharif.edu/status | grep -o '<td>.*</td>'
        sleep 1s # To see login status
    else
        echo "Login failed. Please check your credentials and network connection."
    fi
}

# Function for Sharif IP login
sharif_ip() {
    if [ $# -ne 2 ]; then
        echo "Usage: sharif_ip <username> <password>"
        return 1
    fi
    local username=$(urlencode "$1")
    local password=$(urlencode "$2")
    
    if curl -d "username=${username}&password=${password}" -X POST -k "https://172.17.1.214/login" > /dev/null 2>&1; then
        curl -sk https://172.17.1.214/status | grep -o '<td>.*</td>'
        sleep 1s # To see login status
    else
        echo "IP login failed. Please check your credentials and network connection."
    fi
}

# Function for Sharif logout
sharif_logout() {
    if [ $# -ne 2 ]; then
        echo "Usage: sharif_logout <username> <password>"
        return 1
    fi
    local username=$(urlencode "$1")
    local password=$(urlencode "$2")
    
    if curl -d "username=${username}&password=${password}" -X POST "https://net2.sharif.edu/logout" > /dev/null 2>&1; then
        echo "Logout successful"
        sleep 1s
    else
        echo "Logout failed. Please check your credentials and network connection."
    fi
}

# Define functions for login and IP login with credentials
sharif_login1() {
    sharif_login "YourUsername" "YourPassword"
}

sharif_ip1() {
    sharif_ip "YourUsername" "YourPassword"
}

# Define aliases
alias 1='sharif_login1 && exit'
alias ۱='sharif_login1 && exit'

@pourmand1376
Copy link
Author

New Logout

curl -d "username=test&password=test" -X POST "https://172.17.1.214/logout" --insecure --compressed

New Login:

curl --output /dev/null -d "username=&password=" -X POST "https://172.17.1.214/login" --insecure --compressed > /dev/null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment