#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import socket

def get_local_ip():
    """获取本机IP地址"""
    try:
        # 创建一个socket连接来获取本机IP
        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
        s.connect(("8.8.8.8", 80))
        ip = s.getsockname()[0]
        s.close()
        return ip
    except:
        try:
            # 备用方法
            import subprocess
            result = subprocess.run(['ipconfig'], capture_output=True, text=True, shell=True)
            lines = result.stdout.split('\n')
            for line in lines:
                if 'IPv4' in line and '192.168' in line:
                    return line.split(':')[-1].strip()
        except:
            return '127.0.0.1'

if __name__ == "__main__":
    ip = get_local_ip()
    print(f"🌐 服务器地址信息")
    print(f"="*50)
    print(f"本机IP地址: {ip}")
    print(f"主页面地址: http://{ip}:5000/")
    print(f"移动客户端: http://{ip}:5000/mobile/mobile_client.html")
    print(f"GPS测试页面: http://{ip}:5000/mobile/gps_test.html")
    print(f"设备选择测试: http://{ip}:5000/test_device_selector.html")
    print(f"="*50)
    print(f"�� 手机/平板请访问移动客户端地址！") 