[Python] python获取本机mac地址和ip地址列表 →→→→→进入此内容的聊天室

来自 , 2021-03-03, 写在 Python, 查看 128 次.
URL http://www.code666.cn/view/e41e164f
  1. import sys, socket
  2.  
  3. def getipaddrs(hostname):
  4.     result = socket.getaddrinfo(hostname, None, 0, socket.SOCK_STREAM)
  5.     return [x[4][0] for x in result]
  6.  
  7. # the name of the local machine
  8. hostname = socket.gethostname()
  9.  
  10. try:
  11.     print "IP addresses:", ", ".join(getipaddrs(hostname))
  12. except socket.gaierror, e:
  13.     print "Couldn't not get IP addresses:", e
  14.    
  15.  
  16. #//python/8059

回复 "python获取本机mac地址和ip地址列表"

这儿你可以回复上面这条便签

captcha