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
Method 1: Using uv (Recommended)
# 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
- Configuration Loading - Reads service definitions from
config.py
- Asynchronous Testing - Concurrently pings IP addresses from data files
- Smart Optimization - Uses early termination for large IP sets
- Result Generation - Creates optimized hosts file entries
- 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.