Last active
March 29, 2025 08:03
-
-
Save pourmand1376/965625a56c9e8ba4a82cd6f7dd98ed80 to your computer and use it in GitHub Desktop.
Sharif Login
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
Author
Author
If you are on Windows, just use:
C:\Windows\System32\curl.exe -d "username=YourUserName&password=YourPassword" -X POST "https://net2.sharif.edu/login"You can also edit $profile file and add a function like this there.
function sharif_login
{
C:\Windows\System32\curl.exe -d "username=YourUserName&password=YourPassword" -X POST "https://net2.sharif.edu/login"
}
set-alias a1 sharif_loginNote: It is better to just install wsl.
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"
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'
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
Just add these lines to your
.bashrcor.zshrcand you are good to go.To Login, you can type,
1or ۱orsharif_login1. You can also typesharif_logoutto logout.This script is also useful when you are having problem with DNS. Just type
ip1orsharif_ip1and it will try to login when DNS is problematic.