天天看點

python 十六進制轉換十進制(MAC 轉換 IP 位址)

#!/usr/bin/env python

#-*-coding:utf8-*-

'''C transition to IP address  '''

def macip(argv):

    mac = []

    for i in argv.split(':'):

        mac.append(int(i,16))

    mac="%s.%s.%s.%s.%s.%s" %tuple(mac)

    return mac[6:]

if __name__ == '__main__':

    print macip("00:1c:c0:a8:0a:5b")

    print macip("00:0c:dd:12:da:da")

本文轉自 swq499809608 51CTO部落格,原文連結:http://blog.51cto.com/swq499809608/1227660