Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.024 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'subject:How': 0.10; 'cc:addr:python-list': 0.11; 'jan': 0.12; "''.join(l)": 0.16; 'colons': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:port': 0.16; 'wrote:': 0.18; 'import': 0.22; 'cc:addr:python.org': 0.22; 'skip:l 30': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'code': 0.31; 'mac': 0.33; 'possible.': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'shorter': 0.36; 'subject:?': 0.36; 'too': 0.37; 'that,': 0.38; 'little': 0.38; 'short': 0.38; '12,': 0.39; 'enough': 0.39; 'subject:get': 0.81; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=h8abOtZBjGIXgLOkIR1m6QNrBVhjIRnI+v+wM7J4jjs=; b=rMI9iDzsHFIaBEvn4ULiefLiIBdh3Vh3DSRtQ+m4Dt4EXxxXRh2YpubEmTVXj6MfV9 91lVuwKlSbpTw8J4zxdCJ09VgTQUyVp/r0wBdvG6McB4iI0ITDAzyxDhsUTA0wQLOyzH owAEX5aBIYXn5kxxAhWJcVAVqaQ8LXVh5zM5AQVBF6SW1lhj5EZZQTxfa1vISDswHYUA mhfPoP1vLkFWPJ2snoyTHlmwyM6XC4k+iQuMPRDZEKdRlAPsdeIZepm5gckysp8DQF3n buq14Vj8WMjV1eDShP5sI38jhceHO6KA8D1oxiPsZoKHLXeYhgC147iPVHuOSmp8CbjU 99yg== MIME-Version: 1.0 X-Received: by 10.66.102.39 with SMTP id fl7mr18537065pab.43.1389451932338; Sat, 11 Jan 2014 06:52:12 -0800 (PST) In-Reply-To: References: <6a5ceb3f-021d-4acc-b618-ce53530fa2dd@googlegroups.com> Date: Sun, 12 Jan 2014 01:52:12 +1100 Subject: Re: How to get Mac address of ethernet port? From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 22 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389451941 news.xs4all.nl 2891 [2001:888:2000:d::a6]:36373 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63706 On Sun, Jan 12, 2014 at 1:35 AM, Andriy Kornatskyy wrote: > from uuid import getnode as get_mac > '%012x' % get_mac() > Code golf! Put colons in that, with as little code as possible. # Way too verbose. import uuid l=list("%012x"%uuid.getnode()) l[10:10]=l[8:8]=l[6:6]=l[4:4]=l[2:2]=':' mac = ''.join(l) # Shorter but not short enough import uuid s="%012x"%uuid.getnode() mac = ':'.join(s[i*2:i*2+2] for i in range(6)) :) ChrisA