VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > 编程开发 > python入门 >
  • python入门教程之获取本机的IP地址和mac地址

本站最新发布   Python从入门到精通|Python基础教程
试听地址  
https://www.xin3721.com/eschool/pythonxin3721/


1. 以前一直用ipconfig来查看ip地址,哈哈哈,现在发现挺好玩

复制代码
#获取本机的IP地址和mac地址
import uuid
import socket

def get_mac_address(): 
    mac=uuid.UUID(int = uuid.getnode()).hex[-12:]
    #print(mac)
    return ":".join([mac[e:e+2] for e in range(0,11,2)]) #range(0,11,2):在[0:11]取值,间隔为2

def get_ip_address():
    host_name = socket.getfqdn(socket.gethostname())
    ip_address = socket.gethostbyname(host_name)
    return host_name, ip_address

if __name__ == '__main__':
    mac_address = get_mac_address()
    print('the mac address is: '+mac_address)
    ip_address = get_ip_address()
    print('the host name is: '+ip_address[0])
    print('the ip address is: '+ip_address[1])
复制代码

2. adb查看手机设备信息,参考:https://blog.csdn.net/weixin_43927138/article/details/90477966,https://www.jianshu.com/p/7c0a6da594c8

上述方法我试过了,配置好adb之后:

# 在命令行:cmd下使用

# 第一次连上设备时,使用:
adb devices
# 可以显示设备,之后就不行了,然后再次使用时一直显示:List of devices attached
# 个人觉得是设备的调试开关出了问题,后来经过测试,确认是调试开关的问题,换了一个调试开关没问题的机器就可以了
 
相关教程