Android下获取设备唯一标识(UDID, DeviceID...)

android下获取设备唯一标识原本非常简单(至少不会像iOS一样禁用这个,禁用那个),但是由于设备的多样性需要考虑的东西也对应复杂起来。

先附上完整代码

protected static final String PREFS_FILE = "gank_device_id.xml";  
    protected static final String PREFS_DEVICE_ID = "gank_device_id";
    protected static String uuid;
    static public String getUDID()
    {
    	if( uuid ==null ) {
            synchronized (GankMainActivity.class) {  
                if( uuid == null) {  
                    final SharedPreferences prefs = s_instance.getSharedPreferences( PREFS_FILE, 0);  
                    final String id = prefs.getString(PREFS_DEVICE_ID, null );  
  
                    if (id != null) {  
                        // Use the ids previously computed and stored in the prefs file  
                        uuid = id;  
                    } else {  
  
                        final String androidId = Secure.get
  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
### 回答1: 您可以使用 Python 的网络库,如 `socket` 或 `requests` 库,来获取指定 URL 的 IP 地址。 使用 `socket` 库: ``` import socket def get_ip_address(host): return socket.gethostbyname(host) host = "udid.iosyuan.com" print(get_ip_address(host)) ``` 使用 `requests` 库: ``` import requests def get_ip_address(host): return requests.get("https://" + host).raw._connection.sock.getpeername()[0] host = "udid.iosyuan.com" print(get_ip_address(host)) ``` 上面的代码将会返回该 URL 的 IP 地址。 ### 回答2: 要通过Python获取https://udid.iosyuan.com的真实IP,我们可以使用socket库和requests库来实现。 首先,我们需要使用requests库发送GET请求到https://udid.iosyuan.com,并获取网页的源代码。可以使用以下代码进行请求和获取响应的过程: ```python import requests url = "https://udid.iosyuan.com" response = requests.get(url) source_code = response.text ``` 接下来,我们可以使用正则表达式来提取源代码中的IP地址。由于具体的源代码结构不确定,这里我们只考虑提取合法的IP地址。可以使用以下代码来实现正则表达式匹配: ```python import re ip_pattern = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" ip_list = re.findall(ip_pattern, source_code) ``` 最后,我们可以输出提取到的IP地址。完整的代码如下: ```python import requests import re url = "https://udid.iosyuan.com" response = requests.get(url) source_code = response.text ip_pattern = r"\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" ip_list = re.findall(ip_pattern, source_code) for ip in ip_list: print(ip) ``` 这样我们就可以使用Python获取https://udid.iosyuan.com的真实IP地址了。注意,由于网页的结构可能会发生变化,以上代码可能需要根据实际情况进行调整。 ### 回答3: 使用Python获取https://udid.iosyuan.com的真实IP地址可以通过以下步骤实现: 1. 首先,需要导入所需的库,包括`requests`和`socket`库。可以使用`pip install requests`和`pip install socket`命令进行安装。 2. 创建一个函数来获取真实IP地址,命名为`get_real_ip()`。 3. 在函数中,使用`requests.get()`函数发送一个GET请求到`https://udid.iosyuan.com`网站。 4. 然后,通过`response.text`属性获取响应的HTML内容。 5. 接下来,使用`socket.getaddrinfo()`函数来解析HTML内容中的主机名,获取其对应的IP地址。 6. 最后,将获取到的IP地址返回给调用函数的部分。 下面是一个示例代码: ```python import requests import socket def get_real_ip(): url = 'https://udid.iosyuan.com' response = requests.get(url) html_content = response.text host_name = html_content.split()[2].split("/")[2] ip = socket.getaddrinfo(host_name, None)[0][4][0] return ip # 调用函数并打印真实IP地址 ip_address = get_real_ip() print("真实IP地址是:" + ip_address) ``` 以上代码通过发送GET请求获取网页内容,并从中解析出IP地址。请注意,`getaddrinfo()`函数可能会返回多个IP地址,我们只需使用第一个即可。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值