There are many ways to produce a MAC address under Linux. In addition to the common shell generation method, you can also generate a MAC address by Perl, ruby, etc. The automatic generation method makes a simple summary.
a, the shell generation method
shell generation method is the largest, but also the feeling is the most simple and efficient, there are several methods commonly used tools column randomly generated: < Br>
openssl tool generation
Code is as follows
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 generation
>
Code is as follows
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///& rsquo; -e ‘s//:/g’|
Head -n 1
d8:d3:67:20:c5:f2
for loop generation
The code is as follows
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
Here again, the language itself has no high-level royalties. Don't underestimate the shell, what the shell can do is to use perl, python, php, etc.
Second, perl generation method
Code is as follows
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
The power and simplicity of perl is indisputable.
Third, ruby generation method
Code is as follows
yang@crunchbang:~$ ruby -e ‘puts (1..6).map{“%0.2 X”%rand(256)}.join(“:”)’
CD:97:ED:52:B7:F4
The method used here is almost in perl The same way.
Four, python generation method
Code is as follows
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 and redhat official sites also give a python script:
The code is as follows
#! /usr/bin/python
# macgen.py script to generate a MAC address for Red Hat Virtualization guests
#
import random
#< Br>
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()
When you have the virtinst.util module, you can also use the following simple statement to generate new mac and uuid:
Code is as follows
#! /usr/bin/env python
# -*- mode: python; -*-
print “”
print “New UUID:”< Br>
import virtinst.util ; print virtinst.util.uuidToString(virtinst.util.randomUUID())
print “New MAC:”
import virtinst.util ; Print virtinst.util.randomMAC()
print “”
The above is the method of generating MAC address for Linux. This article introduces four methods to generate MAC address, you can choose The method you like to automatically generate a MAC address.
to change the program icon Unity is a desktop environment interface, mainly used for Ubuntu system,
When the Linux system is performing scheduled tasks, the shell script suddenly stop
After the Linux system is configured with the lnmp environment, there is a problem
Recently, users have reported that the Ubuntu system installed in the virtual machine found that the
How to use the touch command under Linux?
How to solve the problem of Linux system Swap exhaustion
How to install Autossh on Linux system
Linux prompts gzip:stdin:not when extracting tar.gz file?
How to kill pscan2 Trojan under Linux?
Linux system how to use the mount command and software to mount the ISO file
How Linux can view the number of 80 port connections through the netstat command
RHEL6 changes the name of the asm disk by udev.
How to identify Linux system rpm and yum tools
How to solve the problem that the VPN client connection to the Linux server is slow to slow down
Win7 Ultimate has no transparent glass effect how to do
Special Tips for Windows XP System
How to delete the Win7 system desktop IE icon? How to delete IE icon in Win7 system
Windows 7 PSD file format does not display thumbnail solutions
Lenovo notebook black screen does not display images What should I do?
Win8.1 easily played with the built-in SkyDrive network disk function
Solve Windows XP console failure