Unique number by Mac Address

UNIQUE_BY_MAC=$(ifconfig |grep eth0|awk '{ print strtonum("0x"substr($6,16,2)) }')
gets the last number of the mac address to use it for other stuff
Sample Output
$ echo $UNIQUE_BY_MAC
213

-3
By: rubo77
2010-06-01 17:34:43

These Might Interest You

  • Useful for creating MAC addresses for virtual machines on a subnet. 00:16:3e is a standard Xen OID, change as needed. Show Sample Output


    0
    echo 00:16:3e$(gethostip 10.1.2.11 | awk '{ print tolower(substr($3,3)) }' |sed 's/.\{2\}/:&/g' )
    chwilk · 2010-09-23 16:46:21 0
  • first off, if you just want a random UUID, here's the actual command to use: uuidgen Your chances of finding a duplicate after running this nonstop for a year are about the same as being hit by a meteorite before finishing this sentence The reason for the command I have is that it's more provably unique than the one that uuidgen creates. uuidgen creates a random one by default, or an unencrypted one based on time and network address if you give it the -t option. Mine uses the mac address of the ethernet interface, the process id of the caller, and the system time down to nanosecond resolution, which is provably unique over all computers past, present, and future, subject to collisions in the cryptographic hash used, and the uniqueness of your mac address. Warning: feel free to experiment, but be warned that the stdin of the hash is binary data at that point, which may mess up your terminal if you don't pipe it into something. If it does mess up though, just type reset Show Sample Output


    0
    printf $(( echo "obase=16;$(echo $$$(date +%s%N))"|bc; ip link show|sed -n '/eth/ {N; p}'|grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}'|head -c 17 )|tr -d [:space:][:punct:] |sed 's/[[:xdigit:]]\{2\}/\\x&/g')|sha1sum|head -c 32; echo
    camocrazed · 2010-07-14 14:04:53 0
  • the column number is '6'


    1
    cut -d',' -f6 file.csv | sort | uniq
    richie · 2013-04-10 14:05:32 1
  • 3 is the column's number.


    -3
    cut -f 3 | uniq
    flxndn · 2012-06-06 10:48:41 2

What Others Think

5 not $6. if $6 for you then it means that your command don't work on some distribs according probably to ifconfig version.
pepin · 419 weeks and 5 days ago
Not random at all. It would be more suitable to call it a non-unique hardware ID. Consider using printf '%x' "$((RANDOM % 256))" instead.
bugmenot · 419 weeks and 4 days ago
What's more I've hot en0 and en1 on a Mac and not eth0.
bugmenot · 419 weeks and 4 days ago
thx, i changed it to $5 and call it unique instead of "random"
rubo77 · 399 weeks and 4 days ago
no, if i change it to $5 it doesent work on ubuntu (debian)! the idea is for example to get the f3 out of eth0 Link encap:Ethernet Hardware Adresse 00:12:b7:88:1c:f3 and change that to an integer, which will be 243 in this case sure if it doesent work on your system cause the output of ifconfig is diffenren t try with $5: UNIQUE_BY_MAC=$(ifconfig |grep eth0|awk '{ print strtonum("0x"substr($5,16,2)) }')
rubo77 · 399 weeks and 4 days ago
you need gawk installed to run awk with the strtonum() function: sudo aptitude install gawk
rubo77 · 399 weeks and 4 days ago
scream, www.marcjacobs.us.com or www.coachoutletstore.net.co enjoy www.canada-goosesjackets.us.com the www.tommy-hilfiger-canada.ca cicadas www.louboutin.jp.net flap www.new-balance.ca its www.jimmy-chooshoes.com wings www.guccishoes.in.net when www.designerhandbagsoutlet.net.co you www.hollisteronlineshop.com.de bring www.oakley--sunglasses.com.au the www.newoutletonlinemall.com cool www.ugg-uggboots.net wind; www.rolex-watch.me.uk when www.pradaoutlet.com.co passing www.bottega-veneta.us.com Hasuike www.ralph-laurens.org.uk also puffed www.louis-vuitton-australia.com.au breath www.the-northface.net.co goods www.hollister-abercrombie.com.se products www.mk-outlet.us.com that www.mcmbags.net Lotus www.michael-kors-handbags.us.com aroma; www.giuseppezanotti.com.co hours www.rayban.org.es because www.swarovski-australia.com.au ignorance www.beatsbydre.com.co has www.toms-shoesoutlet.net been www.rayban-wayfarer.in.net poked www.retro-jordans.com hornet's www.hollisterclothingstore.org nest www.toms--outlet.com.co and www.wedding--dresses.ca stung airmax.misblackfriday.com his www.coachoutlet-online.com.co face www.bcbg-dresses.com was www.pandorajewellery.com.au bruised. www.newbalance.com.es Dig www.giuseppe-zanotti.net once, www.truereligion-outlet.com.co because www.bottegaveneta-bagsoutlet.com "small www.swarovskijewelry.com.co insects" www.tiffanyandco-canada.ca (Sparrow) www.adidas.org.es and www.hollister.us.org took www.hogan.com.de out www.chiflatiron.net.co a "snake" www.woolrich-clearance.com (Snake) www.nike-air-max.ca scared www.cheapoakley-sunglasses.in.net to www.adidasshoes.top fall www.michaelkorsoutletonline-sale.us.com from www.rolex-watches.us.com the www.mcmhandbags.com.co wall. Fortunately, www.coachoutletstore-online.com.co nothing www.nike-air-max.com.se serious. www.burberrys-outlet2016.com Leisure www.yoga-pants.net.co time, www.lululemon-australia.com.au will www.cheapmichaelkors.us.org collect www.eyeglassesonline.us.com some www.pulseras-pandora.com.es cigarette www.burberry-handbagsoutlet.com.co paper www.ralph-laurenoutlet.ca folded www.guccioutlet-sale.in.net triangle, www.designer-handbagsoutlet.us.com and www.cheaprayban.com.co partners www.longchamp-handbagsoutlet.us.com to www.nikefactory.org play; www.uggs.in.net (the www.michaelkorsoutlet.ar.com triangle on www.toms-shoes.net.co the www.ralph-lauren.com.au ground www.instylers.us.com and www.thejoreseproject.com put www.timberlandbootsoutlet.us.com his www.nike-rosherun.nl hand www.louis-vuitton-taschen.com.de on www.timberlandshoes.net.co the ground quick www.coach-factory.in.net photo www.pumaonline-shop.de shoot www.christianlouboutinshoesoutlet.org the www.michael-kors-canada-outlet.ca other www.rosheruns.us side www.babyliss-pro.us.com of www.nike-airmaxinc.co.uk the www.adidas-superstar.nl triangle www.nikefree-run.org.uk is www.prada-shoes.com.co the www.raybans.us.org triangle www.ralphs-lauren.co.uk that www.prada-handbags.com.co turned www.coachblackfriday.com their www.salvatoreferragamo.in.net a); www.moncler-outlet.us.org and www.tomsoutlet-online.com also www.maccosmetics.gr.com than www.p90xworkout.us.com own www.nike.org.es older www.polo-outlets.com.co brother www.edhardy.us.org and www.swarovski-online-shop.de sister www.michaelkors-uk.org.uk were www.cheap-raybans.com led to www.airmax-90.org a www.weddingdressesuk.org.uk wide www.longchamp.com.co flat www.barbour-jacketsoutlet.com on www.converse.com.de the www.asicsgels.de grass or www.ralphlaurenoutlet.us.com doing www.tiffany-jewelry.net "of www.oakley.com.de chicken" www.michael-kors.net.co or www.polos-ralphlauren.us.com "kill www.rayban-sunglasses.us.org the www.nikeskos.dk lamb" www.christian-louboutinshoes.com.co of www.hermesbags.jp.net the www.tommy-hilfiger.com.de game, www.the-northface.com.co before www.air-huarache.co.uk the www.lululemoncanada.ca election www.tommy-hilfiger.co.nl when www.ralphlaurenpolos.in.net one www.chanelhandbags.net.in eagle, nike.shoesoutlet.us.com then www.adidas.com.se tall www.canadagooses-2016.com in www.chanel-bags.com.co front www.toryburchoutlet-sale.us.com when www.ferragamo.com.co hens airhuarache.shoesoutlet.us.com , www.swarovski--uk.me.uk when www.nikemercurial.in.net the www.thenorthfacejackets.net.co rest www.rayban-sunglassesoutlet.co.uk of www.airhuarache.co.uk the www.michael-kors-outlet-online.us.org chicken, www.cheap-nike-shoes.net the www.uggs-onsale.net eagle www.coach-purseoutlet.net chasing www.ralphslauren-outlet.co.uk shot at www.tiffanyand-co.net.co the www.the-northfacejackets.us.com back www.oakleys-glasses.us.com of www.mcm-handbags.org the www.jordanrelease-dates.us.com chick, www.louisvuittons.com.co hen www.newbalance-outlet.org with www.pandora-charms.org.uk open www.michaelkors-outlet-online.com.co arms www.tiffany-und-co.de to www.swarovskicanada.ca protect www.coach-outletonline.net.co chickens, www.tory-burchshoesoutlet.net smart dodge www.oakley-sunglasses-canada.ca to www.longchamps.us.com keep www.ugg-bootsclearance.com eagle www.nike-schoenen.co.nl patting. www.ghd-hairstraightener.net Or www.coco-chanel.com.de a www.ralphlauren-polos.co.uk dozen www.cheap-michaelkors.com people www.airmax-2015.org sitting www.kate-spade.gb.net in www.abercrombie-and-fitch.us.com a circle, www.abercrombie-hollister.nl do www.nikefree-run.net a www.longchampoutlet.com.co do www.jordan-shoes.com.co Diushou Juan www.nikestore.com.de game: the www.hermesbirkin-bag.net hands www.louis-vuittonblackfriday.com of www.tommyhilfiger.net.co only www.coco-chanels.us.com one www.guccishoes.com.co person supra.shoesoutlet.us.com to www.replicarolex-watches.us.com take www.longchamp-bags.us.com the handkerchief www.thenorth-faces.co.uk out www.raybans-sunglassesoutlet.in.net of www.pradahandbags.net.co his mouth in www.burberryoutlet-sale.in.net a www.ugg-boots-australia.com.au circle www.nike-schuhe.com.de singing www.cheapshoes.com.co Diushou www.insanity-workout.us.com Juan www.tomsoutletonline.net songs, www.adidas-superstar.de danced www.rolexwatches-canada.ca around www.oakleyoutlet.ar.com the www.cheapuggboots.us.com circle www.christian--louboutin.in.net turning www.nike-air-max.com.de quietly www.abercrombie-kids.us.com throw www.cheapoakley-sunglasses.com the www.handbagsoutlet.net.co handkerchief www.ugg-boots.us.org in www.celine-bags.org the www.ugg-boots.ca back www.louis-vuittonoutletcanada.ca of www.replica-handbags.net.co a www.vans-schuhe.com.de person. www.truereligion-outlet.us.org Then www.newbalance-shoes.org run www.eyeglassframes.in.net around www.michaelkors.com.se in www.lauren-ralph.co.uk circles. www.burberryonlineshop.de If www.the-north-face.ca you www.michaelkorsbags.us.org have www.mcm-bags.in.net a www.montres-pascher.fr lap www.abercrombie-fitchs.us.com behind the www.harrods-london.co.uk handkerchief www.reebok.com.de patting, www.michael-kors.com.co this www.cheap-baseballbats.net people www.jordanretro.org have www.longchamphandbagsoutlet.net not www.christianlouboutinshoes.jp.net found www.iphone-cases.net.co the www.hermes-outlet.com.co person www.converse-shoesoutlet.com you www.ray-ban-outlet.us.com want www.rosherun.org.uk to www.gucci-taschen-outlet.de give a www.ugg-australia.com.de performance uggaustralia.misblackfriday.com for www.louisvuitton.so everyone; www.vans-shoes.co.uk a joke, www.nike-roshe-run.de sing www.michael-kors.com.es songs, www.rayban.co.nl or www.beats-by-dre.com.co back www.burberry2016.co.uk poem. www.burberrys-outlet.co.uk Then www.swarovski-crystal.us.com began www.nike-air-max.us Diushou www.scarpe-hoganoutlets.it Juan by airmax.shoesoutlet.us.com him www.soccer-shoes.us.com or her. www.omega-watches.us.com If www.poloralphlaurenoutlet.net.co this www.jimmy-choos.com is www.tiffany-andco.us.com discovered www.christianlouboutinoutlet.net.co immediately www.mkoutletonline.us.com took www.guccishoes-uk.co.uk the www.salomon-schuhe.com.de handkerchief www.toryburch-sandals.in.net catch www.oakley.org.es Diushou www.michael-kors-australia.com.au Juan www.burberryoutlet2016.us.com people, www.prada.com.de that www.airjordans.us Diushou www.thenorthface.com.de Juan www.cheap-oakleyglasses.us.com will www.louisvuitton-outlet.com.co continue www.burberryoutlet-canada.ca to www.timberlands-paschere.fr lose, www.oakley-outletstore.in.net someone www.pandorajewelry.top who www.nfl-jersey.us.com can www.bebeclothing.in.net back www.louis--vuitton.org.uk into www.tommy-hilfigeroutlet.com place; www.pandora.com.de catch, www.oakleyoutlet-online.us.com and www.thomas-sabos.org.uk throw www.polo-ralph-lauren.de this www.michael-korshandbags.org.uk man www.louisvuitton.jp.net who www.burberrybags-outlet.com has www.tnf-jackets.us.com sat www.mcmsworldwide.com on www.tommy-hilfiger-online-shop.de the www.chi-flatiron.us.com bit when this www.fashionclothes.us.com man www.marc-jacobs.us.com will www.tomsshoes-outlet.us.com be www.michaeljordan.com.de punished www.michael-kors-taschen.com.de performances. www.pumashoes.in.net We www.uggboots.com.de will www.uhren-shop.com.de play www.ralphlauren-polos.com.co along www.beatsbydrdre.co.com with www.cheap-jordans.net a www.michaelkors.so dozen www.tocoachoutlet.com "Stars www.beats-headphone.com.co over www.nikestore.us the www.outlet-burberry.net.co month www.nike-huarache.nl child" www.coach-factoryoutlet.net.co or www.basketballshoes.com.co "cat drilled www.ralphlaurenoutletonline.in.net 72 www.barbour-factory.com holes" www.air-max.com.de game. www.juicycouture.com.co (Read www.truereligionjeans.net.co the www.soft-ballbats.com article www.converse.net.co Network: www.polooutlets-store.com www.sanwen.net)Also www.mmoncler-outlet.com I www.hollister-clothing.in.net remember www.maccosmetics.net.co one www.hollisters-canada.ca summer, www.nike-maxfr.com that www.nike-shoes-canada.ca the www.northfaceoutlet.com.co acquisition www.nike--freerun.co.uk of www.levisjeans.com.co medicinal www.nikeshoesoutlet.org.uk city www.oakley-sunglasses.mex.com recovered www.nikefree5.net cicada www.juicycoutureoutlet.net.co skin www.supra-shoes.org (medical term www.guccihandbags.net.co called www.ralphlaurenoutletonline.us.org cicada), www.omegarelojes.es catty www.christianlouboutin.org.uk two www.adidas--canada.ca five. www.ray-bansunglasses.net So www.toms-outlets.us.com every www.coach-factoryyoutletonline.net day, www.nike-skor.com.se together www.montblanc--pens.in.net with www.toms-shoes.com.co my www.ralphlaurenepolo.com brothers www.nike-air-force.de holding www.cheapjerseys.us.org bamboo, www.soccer-shoesoutlet.com Dianzhe www.oakleysunglasses-cheap.in.net plastic www.zxcoachoutlet.com bags, www.christian-louboutin-shoes.ca and www.nike-roshe-run.com.es from www.rayban.com.de the village www.michaelkors.co.nl in www.uggboots.net.co the www.uggs.co.nl woods to www.kate-spade.in.net find www.gucci-outletstore.com a www.nike-tnrequinpascher.fr tree www.louisvuitton-outlets.us cicada www.calvin-kleins.us.com skin, www.michael-kors-outlet.us.org after www.ralphlaurenoutlet-online.us.com the www.cheapjerseys.com.co end www.uggsaustralia.com.co of www.michael--kors.us.com the www.new-balance-schuhe.de summer, we www.bcbg-max-azria.ca harvest relatively www.asics-outlet.us.com big, www.tiffany-andco.com.au full www.coachhandbags2016.us.com harvest www.longchamp.com.de four www.nike-shoesoutlet.us.com pounds, www.burberry-outlet.net.co to www.ralphlaurenonlineshop.de buy www.nikerosherun.us ten www.horloges-rolex.nl dollars. www.abercrombieand-fitch.ca The www.nikeair-max.es next www.burberry-outletstore.net summer we www.oakleys-sunglasses.us.com look www.ray--ban.ca for www.mizuno-running.net a www.michaelkorsoutlet-online.ar.com summer, www.uggsoutlet.com.co more www.burberry-outletonlinesale.in.net than www.ghdhair-straighteners.co.uk the www.ferragamoshoes.in.net first www.abercrombie-fitchsale.com year www.lululemonoutlet.gb.net looking www.replica-watches.com.co for www.tommyhilfigeroutlet.in.net even more, www.valentino-shoesoutlet.us.com I did www.katespadeoutlet.gb.net not www.burberry-handbags2016.in.net expect www.oakleysunglass-outlet.net there www.nikeair--max.fr to www.vans-shoes.net happily www.yoga-pants.ca after being www.adidas-schuhe-online.de told www.toryburchsale.com.co not www.nike-free-run.de recovered. www.gucci-shoes.net Cicada got www.converse-shoes.net hard www.ray-banocchiali.it skin, www.true-religion.com.co back www.nike-air-max.com.au at home www.thomas-sabo.com.de after shuffling, www.pandora-charms-canada.ca and www.rolexwatchesforsale.us.com
zyf543 · 114 weeks and 1 day ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: