# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 50:E5:49:3A:EA:90
inet addr:172.28.10.71 Bcast:172.28.10.255 Mask:255.255.255.0
inet6 addr: fe80::52e5:49ff:fe3a:ea90/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3457606 errors:0 dropped:0 overruns:0 frame:0
TX packets:255283 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:503195543 (479.8 MiB) TX bytes:30327237 (28.9 MiB)
MAC地址是50:E5:49:3A:EA:90
IP地址是172.28.10.71
现用python的方式来获取它们
def get_max_address():
import uuid
node=uuid.getnode()
mac=uuid.UUID(int=node).hex[-12:]
return mac
输出结果:
50e5493aea90
def get_ip():
args='''ifconfig|grep 'inet addr:'|awk '{print $2}'|awk -F':' '{print $2}'|grep -v "127.0.0.1"'''
t=subprocess.Popen(args,shell=True,stdout=subprocess.PIPE).communicate()[0]
return t.split('\n')[0]
输出结果为:
172.28.10.71
参考文章:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有