sweetomy
V2EX  ›  问与答

如何生成随机的 mac 地址 且第二位必须是偶数

  •  
  •   sweetomy · Mar 9, 2015 · 2814 views
    This topic created in 4115 days ago, the information mentioned may be changed or developed.
    网上是这样生成的 openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' 但有时第二位不是偶数 郁闷
    5 replies    2015-03-10 11:01:26 +08:00
    ryd994
        1
    ryd994  
       Mar 9, 2015 via Android
    生成一个,验证如果不是就重新生成
    检查第二位不难吧
    Septembers
        2
    Septembers  
       Mar 9, 2015
    echo "from random import randint, choice; mac = map(lambda _: randint(0, 0xFF), xrange(6)); mac[2] = choice(range(0, 255, 2)); print ':'.join(map(lambda x: '%02x' % x, mac))" | python

    see https://www.centos.org/docs/5/html/5.2/Virtualization/sect-Virtualization-Tips_and_tricks-Generating_a_new_unique_MAC_address.html
    sweetomy
        3
    sweetomy  
    OP
       Mar 10, 2015
    @Septembers 第二位不是偶数
    invite
        4
    invite  
       Mar 10, 2015
    你需要用哪类代码生成。
    sweetomy
        5
    sweetomy  
    OP
       Mar 10, 2015
    @invite 随便呀
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   807 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 21:33 · PVG 05:33 · LAX 14:33 · JFK 17:33
    ♥ Do have faith in what you're doing.