天天看點

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

#!/usr/bin/env python

#-*-conding:utf8-*-

def emac(argv):

 emac = []

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

  try:

   if int(i) <= 255:

    emac.append(hex(int(i))[2:])

   else :

    print "Please input the vorrect address! "

  except TypeError, e:

   pass

 emac="00:1c:%s:%s:%s:%s" %tuple(emac)

 return emac

def imac(argv):

 imac = []

    imac.append(hex(int(i))[2:])

 imac="00:1c:%s:%s:%s:%s" %tuple(imac)

 return imac

if __name__ == "__main__":

 print '192.168.10.223::%s' %(emac('192.168.10.233'))

 print '192.168.10.227::%s' %(imac('192.168.10.227'))

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