将十六进制MAC地址转换为用户可读格式(Python)(Convert Hexadecimal MAC address to user readable formatting (Python))

编程入门 行业动态 更新时间:2024-10-25 10:31:44
将十六进制MAC地址转换为用户可读格式(Python)(Convert Hexadecimal MAC address to user readable formatting (Python))

我从套接字收到这种格式的MAC地址:0024e865a023(十六进制转换为二进制,带有received-string.encode(“hex”))

我想将其转换为用户可读格式,如:00-24-e8-65-a0-23

有什么简单的方法吗?

I'm receiving from the socket a MAC address in this format: 0024e865a023 (hex converted from binary with received-string.encode("hex"))

I would like to convert it to a user readable format like this : 00-24-e8-65-a0-23

Any easy way to do so?

最满意答案

您可以将MAC地址拆分为每个块的数组,然后将它们连接到- :

mac = '0024e865a023' blocks = [mac[x:x+2] for x in xrange(0, len(mac), 2)] macFormatted = '-'.join(blocks)

You can break apart the MAC address into an array of each block, and then join them on -:

mac = '0024e865a023' blocks = [mac[x:x+2] for x in xrange(0, len(mac), 2)] macFormatted = '-'.join(blocks)

更多推荐

本文发布于:2023-08-07 10:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463694.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   可读   地址   格式   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!