python 十进制转换十六进制 (ip地址转换MAC地址)

本文涉及的产品
公网NAT网关,每月750个小时 15CU
简介:

#!/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 = []
 for i in argv.split('.'):
  try:
   if int(i) <= 255:
    imac.append(hex(int(i))[2:])
   else :
    print "Please input the vorrect address! "
  except TypeError, e:
   pass
 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

相关文章
|
1月前
|
缓存 API 定位技术
使用Python调用百度地图API实现地址查询
使用Python调用百度地图API实现地址查询
98 0
|
1月前
|
网络协议 网络安全 数据库
python验证公网ip与内网ip
python验证公网ip与内网ip
25 0
|
1月前
|
数据采集 安全 数据安全/隐私保护
python怎么获取免费代理IP
python怎么获取免费代理IP
47 0
|
1月前
|
存储 Python
|
3天前
|
数据挖掘 API 数据安全/隐私保护
python请求模块requests如何添加代理ip
python请求模块requests如何添加代理ip
|
4天前
|
存储 关系型数据库 MySQL
Python搭建代理IP池实现存储IP的方法
Python搭建代理IP池实现存储IP的方法
|
4天前
|
Python
Python动态IP代理防止被封的方法
Python动态IP代理防止被封的方法
|
4天前
|
存储 API Python
python之代理ip的配置与调试
python之代理ip的配置与调试
|
4天前
|
存储 Python
用Python实现批量下载文件——代理ip排除万难
用Python实现批量下载文件——代理ip排除万难
|
4天前
|
数据采集 API Python
python关于ip代理池的获取和随机生成
python关于ip代理池的获取和随机生成