Skip to content

MPCodeWriter21/UT-Internet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌐 UT Internet Login Script

PowerShell License Version Release Downloads

A powerful and user-friendly PowerShell script for managing University of Tehran (UT) network authentication. This script simplifies the login process with features like credential management, session control, and traffic monitoring.


✨ Features

  • 🔐 Secure Credential Management: Save your credentials securely for future use
  • 🔄 Smart Session Detection: Automatically detects if you're already logged in
  • 👥 Multi-Account Support: Add and manage multiple UT accounts
  • 🚪 Session Management: Log out from active sessions with ease
  • 📊 Traffic Monitoring: View your remaining internet traffic quota
  • 🔌 Multi-Session Handling: Disconnect other active sessions when needed
  • 🤖 Automatic CAPTCHA Solving: Uses Tesseract OCR to automatically solve CAPTCHAs
  • 🔔 Automatic Update Check: Notifies you when a new version is available on GitHub
  • 🎨 Colorful Interface: Beautiful, color-coded output for better readability
  • ⚙️ Flexible Options: Multiple command-line flags for customized behavior

📋 Table of Contents


Requirements

  • Operating System: Windows
  • PowerShell: Version 5.1 or higher
  • Network: Connected to the University of Tehran network
  • Permissions: Ability to make HTTPS requests
  • Tesseract OCR: Optional but recommended - Required for automatic CAPTCHA solving (traffic monitoring and session management)

To check your PowerShell version:

$PSVersionTable.PSVersion

Installing Tesseract OCR

Tesseract is required for automatic CAPTCHA solving when checking traffic or disconnecting other sessions.

Official Repository: tesseract-ocr/tesseract

Installation Guide: Tesseract Installation Documentation

Quick Install Options:

Option 1: Using Chocolatey (Recommended)

choco install tesseract

Option 2: Manual Installation

  1. Download from UB Mannheim Tesseract (Windows installers)
  2. Install and add to PATH
  3. Verify installation: tesseract --version

For other platforms and detailed instructions, see the official installation guide.


Installation

Method 1: Download from Releases (Recommended)

Download the latest version from the Releases page:

  1. Download login-to-internet.cmd
  2. Double-click to run
  3. Perfect for users unfamiliar with PowerShell

Method 2: Clone Repository

# Clone the repository
git clone https://github.com/yourusername/UT-Internet.git

# Navigate to the directory
cd UT-Internet

# Run the script
.\login-to-internet.ps1

Usage

Basic Usage

Simply run the script in PowerShell:

.\login-to-internet.ps1

On first run, you'll be prompted to enter your username and password. By default, credentials are saved securely for future use.

Command-Line Options

Flag Description
-reset Reset saved credentials and prompt for new ones
-noSave Don't save credentials (prompt every time)
-addAccount Add a new account to saved credentials
-chooseDefault Set or unset the default account
-chooseAccount Select an account for this session (keeps default unchanged)
-noRemainingTraffic Skip displaying remaining traffic quota
-noUpdateCheck Skip checking for updates on GitHub
-help Display help message with usage information
-version Display script version

Features in Detail

1. Secure Credential Storage

Your credentials are encrypted using PowerShell's built-in ConvertFrom-SecureString cmdlet and stored in a hidden system file. The credentials are encrypted with your Windows user account, making them inaccessible to other users.

Security measures:

  • Credentials encrypted with user-specific key
  • Hidden system file

2. Automatic Session Detection

The script intelligently detects if you're already logged in to the UT network by parsing the portal response. If you're logged in, it offers to:

  • Show your current session status
  • Display remaining traffic
  • Log you out if desired

3. Multi-Session Management

If login fails due to too many active sessions, the script can:

  • Detect the conflict automatically
  • Offer to disconnect other sessions
  • Retry login after disconnecting

4. Traffic Monitoring

View your remaining internet quota in human-readable format:

  • Automatically converts UNITS to MB/GB/TB
  • Color-coded output for easy reading
  • Automatic CAPTCHA solving using Tesseract OCR

5. Automatic Update Check

After successful login, the script automatically checks GitHub for new releases:

  • Compares your version with the latest release on GitHub
  • Displays a notification box if an update is available
  • Shows current version, latest version, and download link
  • Includes brief release notes preview
  • Can be disabled with the -noUpdateCheck flag

Example output when an update is available:

  ===========================================================================
 |                            UPDATE AVAILABLE!                              |
  ===========================================================================
 |  Current Version: 1.2.0                                                   |
 |  Latest Version:  1.2.1                                                   |
  ============================================================================
 |  Download: https://github.com/MPCodeWriter21/UT-Internet/releases/latest  |
  ============================================================================
 |  What's Changed:                                                          |
 |  #### Commits since v1.2.0:                                               |
 |  - fix: Removed unnecessary empty lines for better readability (3e9cc70)  |
  ===========================================================================
 [i] Use '-noUpdateCheck' flag to disable update notifications.

6. Smart DNS Resolution

The script uses multiple DNS servers to resolve the login portal:

  • Primary DNS: 192.168.20.14
  • Secondary DNS: 192.168.20.15
  • Fallback: System default DNS

This ensures reliable connection even if one DNS server is down.


How It Works

Login Process Flow

graph TD
    A[Start Script] --> B{Saved Credentials?}
    B -->|Yes| C[Load Credentials]
    B -->|No| D[Prompt for Credentials]
    C --> E[Resolve DNS]
    D --> E
    E --> F{DNS Resolved?}
    F -->|No| G[Error: Check Connection]
    F -->|Yes| H[Get Magic Token]
    H --> I{Already Logged In?}
    I -->|Yes| J[Offer Logout]
    I -->|No| K[Send Login Request]
    K --> L{Login Success?}
    L -->|Yes| M[Show Traffic]
    L -->|No| N{Too Many Sessions?}
    M --> R[Check for Update]
    N -->|Yes| O[Disconnect Other Sessions]
    N -->|No| P[Show Error]
    O --> K
    R --> Q[End]
    J --> Q
    P --> Q
    G --> Q
Loading

Troubleshooting

Common Issues and Solutions

❌ "Failed to find IP for the login server"

Cause: Not connected to UT network or DNS issues

Solutions:

  • Verify you're connected to the UT network (WiFi or LAN)
  • Disable VPN clients and clear proxies
  • Check firewall settings

❌ "Failed to retrieve magic token"

Cause: Portal connectivity issues

Solutions:

  • Verify your internet connection stability
  • Try again in a few moments

❌ "Failed to login for some reason"

Cause: Incorrect credentials or issue with UT login system

Solutions:

  • Use the -reset flag to enter credentials again
  • Verify your username and password are correct
  • Check if your account is active
  • Try again later

❌ "Tesseract OCR is not installed or not found in PATH"

Cause: Tesseract OCR is missing or not accessible

Solutions:

  • Install Tesseract OCR (see Requirements section)
  • Verify Tesseract is in your system PATH: tesseract --version
  • Restart PowerShell after installation
  • Note: This only affects traffic monitoring and session disconnection features

❌ Execution Policy Error

Error: cannot be loaded because running scripts is disabled

Solution:

# Run PowerShell as Administrator
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Security

Credential Storage

  • Credentials are encrypted using Windows Data Protection API (DPAPI)
  • Only your Windows user account can decrypt the stored credentials
  • Credentials file is hidden and marked as system file

Credential Deletion

To remove saved credentials:

.\login-to-internet.ps1 -reset

Best Practices

  • ✅ Use strong, unique passwords
  • ✅ Only save credentials on your personal computer
  • ✅ Use -noSave flag on shared/public computers
  • ✅ Keep your Windows account password protected
  • ❌ Don't run the script on untrusted systems

Contributing

Contributions are welcome! Here's how you can help:

Reporting Bugs

Open an issue with:

  • Script version
  • PowerShell version
  • Error messages
  • Steps to reproduce

Suggesting Features

Open an issue describing:

  • The feature you'd like to see
  • Why it would be useful
  • How it should work

Pull Requests

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Copyright (C) 2024-2025 CodeWriter21 - Mehrad Pooryoussof

This project is licensed under the MIT License - see the LICENSE file for details.


Author

Mehrad Pooryoussof (CodeWriter21)


Additional Resources

PowerShell Resources


Roadmap

Future enhancements planned:

  • Multiple account support (Added in v1.1.0)
  • Automatic update notifications (Added in v1.3.0)
  • Bypass acct captcha (Added in v1.4.0 - Tesseract OCR integration)
  • Automatic login on network connection
  • Traffic usage statistics and history
  • Scheduled auto-login
  • Add additional methods of solving captcha (Use ocr.space API, manual input from the user)
  • Cross-platform support (Linux/macOS)

Show Your Support

If this script helped you, please consider:

  • ⭐ Starring the repository
  • 🐛 Reporting bugs
  • 💡 Suggesting new features
  • 📢 Sharing with others

Changelog

Version 1.4.1 (Latest)

Bug Fixes and Code Improvements

  • Enhanced DNS resolution - Added proper error handling for unexpected IP address types
  • Improved type checking - Better handling of different DNS response formats (array vs string)
  • Better diagnostics - Clear error messages when DNS resolution returns unexpected data types

Technical Details:

  • Fixed type checking in Get-Ip function for IPAddress objects
  • Added exception handling with descriptive messages for unexpected types
  • Improved fallback DNS resolution with proper type detection
  • Ensures script fails gracefully with informative errors instead of silent failures

Version 1.4.0

Automatic CAPTCHA Solving Release

  • Tesseract OCR integration - Automatically solves CAPTCHAs using Tesseract OCR engine
  • Traffic monitoring restored - Re-enabled automatic traffic display with CAPTCHA bypass
  • Session management restored - Re-enabled automatic session disconnection with CAPTCHA bypass
  • Smart username handling - Automatically removes @ut.ac.ir suffix from usernames
  • Graceful fallback - Clear error messages if Tesseract is not installed
  • Temporary file cleanup - Automatically removes downloaded CAPTCHA images

Technical Details:

  • Downloads CAPTCHA image from acct.ut.ac.ir
  • Uses Tesseract OCR with optimal settings (--oem 3 --psm 6)
  • Stores temporary CAPTCHA in system temp folder
  • Cleans up after processing
  • Maintains session cookies for authenticated requests

Requirements:

  • Tesseract OCR must be installed and in PATH
  • See Requirements section for installation instructions

Version 1.3.2

User Experience Improvements

  • Clear error messages - Added understandable error messages explaining captcha protection on the account server
  • Traffic monitoring - Temporarily disabled automatic traffic display due to captcha protection
  • Session disconnection - Temporarily disabled automatic session disconnection due to captcha protection
  • User guidance - Directs users to web portal for traffic checking and session management while working on a solution

Note: The account server now has captcha protection. Traffic monitoring and automatic session disconnection features are temporarily unavailable through the script. Users are advised to use the web portal for these functions.

Version 1.3.1

Bug Fixes and Improvements

  • Make sure to use -UseBasicParsing flag with Invoke-WebRequest to avoid executing scripts and suppress security warning message.

Version 1.3.0

Automatic Update Check Release

  • GitHub update notifications - Automatically checks for new releases after login
  • Release notes preview - Shows brief release notes from the latest version
  • Configurable - Use -noUpdateCheck flag to disable update notifications

New Flag:

  • -noUpdateCheck - Skip checking for updates on GitHub

Behavior:

  • After successful login and traffic display, queries GitHub API for latest release
  • Compares current version (1.3.0) with latest available version
  • Displays formatted notification box if update is available
  • Shows download link and first few lines of release notes
  • Never interrupts workflow if update check fails

Version 1.2.1

UI/UX Polish Release

  • Cleaner interface - Removed unnecessary empty lines for better readability
  • GitHub link added - Added repository link to header banner
  • Minor spacing improvements - Improved visual flow throughout the script

Changes:

  • Added GitHub repository URL to copyright banner
  • Removed redundant Write-Host calls that created excessive blank lines
  • Improved output spacing in -chooseDefault and -chooseAccount flags
  • Cleaner output when displaying remaining traffic

Version 1.2.0

Flexible Default Account Release

  • Null default option - Set default to "None" to be prompted on each login
  • Auto-select single account - Single account users never prompted
  • Smart migration - Automatically migrates v1.1.0 multi-account users to null default
  • Improved UX - Helpful tips and prompts for multi-account management

Enhanced Flags:

  • -chooseDefault now supports "None" option (option 0)

Behavior:

  • Multi-account users with null default: Prompted to choose account each time
  • Single account users: Automatically selected without prompting
  • Multi-account users with set default: Use default account automatically

Version 1.1.0

Multi-Account Support Release

  • Multi-account management - Add and manage multiple UT accounts
  • Default account selection - Set your preferred default account
  • Per-session account choice - Use different accounts without changing default
  • Automatic migration - Seamlessly updates old credential format
  • Account password updates - Update passwords for existing accounts

New Flags:

  • -addAccount - Add a new account
  • -chooseDefault - Set default account
  • -chooseAccount - Choose account for current session

Version 1.0.0

Initial Public Release

  • Basic login functionality
  • Credential management
  • Session detection and management
  • Traffic monitoring
  • Multi-session handling
  • Colorful user interface
  • Command-line options

Made with ❤️ for University of Tehran Students

If you find this useful, don't forget to star the repo! ⭐

About

Simple script to help you with logging in to internet.ut.ac.ir

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors