MicrosoftHostsPicker

A modern, asynchronous Python tool to automatically find and select the fastest IP addresses for Microsoft services.

A modern, asynchronous Python tool to automatically find and select the fastest IP addresses for Microsoft services.

πŸš€ Features

  • Asynchronous ping testing - Concurrent latency testing for faster results
  • Smart IP selection - Intelligent early termination when optimal IPs are found
  • Modular configuration - Easy-to-customize service definitions
  • Beautiful console output - Rich, colorful progress indicators and results
  • Modern Python - Built with asyncio, type hints, and dataclasses

🎯 Why This Tool?

In certain regions, Microsoft services may experience poor performance due to DNS resolving to suboptimal IP addresses. This tool solves that problem by:

  • Testing hundreds of IP addresses concurrently
  • Identifying the lowest-latency endpoints for each service
  • Generating optimized hosts file entries
  • Supporting 10+ Microsoft services including Xbox Live, Office CDN, Microsoft Store, and more

πŸ“‹ Supported Services

  • Microsoft Account - account.microsoft.com
  • Xbox Live CDN - Game content delivery and multiplayer services
  • Xbox Cloud Sync - Save game synchronization
  • Office CDN - Office application downloads and updates
  • Microsoft Store - App store images and pages
  • Microsoft Games Download - Game installation and updates
  • Windows Update - System updates and patches
  • Microsoft Login - Authentication services (static IP)

πŸ› οΈ Installation

Prerequisites

  • Python 3.12+
  • Network connectivity for ping testing
# Install uv if you haven't already
pip install uv

# Clone the repository
git clone https://github.com/WayneXuCN/MicrosoftHostsPicker.git
cd MicrosoftHostsPicker

# Install dependencies
uv sync

Method 2: Using pip

# Clone the repository
git clone https://github.com/WayneXuCN/MicrosoftHostsPicker.git
cd MicrosoftHostsPicker

# Install dependencies
pip install ping3==4.0.4

πŸš€ Usage

Basic Usage

python MicrosoftHostsPicker.py

Advanced Configuration

You can customize the behavior by modifying config.py:

DEFAULT_CONFIG = {
    'ping_attempts': 2,           # Number of ping attempts per IP
    'ping_timeout': 0.5,          # Ping timeout in seconds
    'ping_max_workers': 100,      # Concurrent ping limit
    'good_enough_threshold': 50.0, # Stop testing if latency < 50ms
}

πŸ“ Project Structure

MicrosoftHostsPicker/
β”œβ”€β”€ MicrosoftHostsPicker.py    # Main application
β”œβ”€β”€ config.py                  # Service configurations
β”œβ”€β”€ pyproject.toml            # Project metadata and dependencies
β”œβ”€β”€ uv.lock                   # Lock file for reproducible builds
β”œβ”€β”€ data/                     # IP address databases
β”‚   β”œβ”€β”€ Microsoft_Account.txt
β”‚   β”œβ”€β”€ Xbox_Live_CDN_1.txt
β”‚   └── ...
└── hosts                     # Generated hosts file (after running)

πŸ”§ How It Works

  1. Configuration Loading - Reads service definitions from config.py
  2. Asynchronous Testing - Concurrently pings IP addresses from data files
  3. Smart Optimization - Uses early termination for large IP sets
  4. Result Generation - Creates optimized hosts file entries
  5. User Guidance - Provides clear instructions for implementation

πŸ“– Usage Tips

  • Selective Application: Only replace problematic IP addresses in your system’s hosts file
  • Backup First: Always backup your existing hosts file before making changes
  • Service-Specific: Some services use global CDN and may not need manual configuration
  • Regular Updates: Re-run the tool periodically as optimal IPs may change

πŸ” Understanding the Output

The tool provides rich console output:

  • βœ… Green checkmark: Optimal IP found
  • ❌ Red X: No available IP found
  • ⚠️ Warning: Test failed
  • πŸ“Š Progress bar: Shows testing progress for large IP sets

πŸ›‘οΈ System Hosts File Locations

  • Windows: C:\Windows\System32\drivers\etc\hosts
  • macOS/Linux: /etc/hosts

Remember to run as administrator/sudo when modifying system hosts files.

πŸ™ Acknowledgments

This project is based on ButaiKirin/MicrosoftHostsPicker. Thanks to the original author for the foundation work.

🀝 Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

πŸ“„ License

This project is licensed under the terms specified in the LICENSE file.

This page was automatically translated by generative AI and may contain inaccuracies or incomplete information. Feedback is welcome to help us improve.