Linux高消费MAC天址的要领有不少种,除了了常睹的shell熟成法中,借能经由过程Perl、ruby等要领去熟成MAC天址,上面小编对MAC天址的主动熟成要领作了简略的汇总。
1、shell熟成法
shell熟成的要领是至多的的,异时也觉得也是最为简略下效的,那面列几种罕用东西随机熟成的要领:
openssl东西熟成
代码以下
yang@crunchbang:~$ openssl rand -hex 6 | sed ‘s/(。。)/1:/g; s/.$//’
a0:77:d4:ef:08:7d
yang@crunchbang:~$ openssl rand 6 | xxd -p | sed ‘s/(。。)/1:/g; s/:$//’
3b:7f:95:c8:39:6d
od熟成
代码以下
yang@crunchbang:~$ od -An -N10 -x /dev/random | md5sum | sed -r ‘s/^(。{10}).*$/1/; s/([0-9a-f]{2})/1:/g; s/:$//;’
b0:85:1a:41:b1
yang@crunchbang:~$
yang@crunchbang:~$ od /dev/urandom -w6 -tx1 -An|sed -e ‘s/ //’ -e ‘s/ /:/g’|head -n 1
d8:d3:67:20:c5:f2
for轮回熟成
代码以下
yang@crunchbang:~$ for i in {1..6}; do printf “%0.2X:” $[ $RANDOM % 0x100 ]; done | sed ‘s/:$/n/’
8E:9E:FB:AE:FF:D2
yang@crunchbang:~$ h=0123456789ABCDEF;for c in {1..12};do echo -n ${h:$(($RANDOM%16)):1};if [[ $((c%2)) = 0 && $c != 12 ]];then echo -n :;fi;done;echo
19:7F:A9:41:E2:20
那面再次感慨高,言语自身出有下级贱贵,没有要不放在眼里了shell,shell能真现的湿吗非失要用perl、python、php等来真现。
2、perl熟成法
代码以下
yang@crunchbang:~$ perl -e ‘printf(“%.2x:”,rand(255))for(1..5);printf(“%.2xn”,rand(255))’
f8:42:c1:d4:a8:28
yang@crunchbang:~$ perl -e ‘print join(“:”, map { sprintf “%0.2X”,rand(256) }(1..6))。“n”’
A7:02:BD:BC:59:E2
perl的壮大取简约无否争辩 。
3、ruby熟成法
代码以下
yang@crunchbang:~$ ruby -e ‘puts (1..6).map{“%0.2X”%rand(256)}.join(“:”)’
CD:97:ED:52:B7:F4
那面运用的要领简直战perl外的要领同样。
四、python熟成法
代码以下
yang@crunchbang:~$ python -c “from itertools import imap; from random import randint; print ‘:’.join([‘%02x’%x for x in imap(lambda x:randint(0,255), range(6))])”
52:75:80:68:3a:cc
centos战redhat民间站点上也给没了一个python剧本:
代码以下
#!/usr/bin/python
# macgen.py script to generate a MAC address for Red Hat Virtualization guests
#
import random
#
def randomMAC():
mac = [ 0x00, 0x16, 0x3e,
random.randint(0x00, 0x7f),
random.randint(0x00, 0xff),
random.randint(0x00, 0xff) ]
return ‘:’.join(map(lambda x: “%02x” % x, mac))
#
print randomMAC()
正在有virtinst.util模块时,也能够运用上面的简略语句熟成新的mac战uuid:
代码以下
#!/usr/bin/env python
# -*- mode: python; -*-
print “”
print “New UUID:”
import virtinst.util ; print virtinst.util.uuidToString(virtinst.util.randomUUID())
print “New MAC:”
import virtinst.util ; print virtinst.util.randomMAC()
print “”
下面便是Linux熟成MAC天址的要领引见了,原文一共引见了四种要领熟成MAC天址,您能够选择您怒悲的要领去主动熟成MAC天址。
相关文章