login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > Overige > CGI en Perl > Convert mac address

Convert mac address

Auteur: Slipie - 10 mei 2006 - 10:27 - Gekeurd door: Rens - Hits: 3443 - Aantal punten: (0 stemmen)





Dit scriptje converteerd een mac adres van standaard formaat naar cisco formaat en visa versa.
Handig voor system administrators die veel tussen deze formaten moeten switchen.

Het is te gebruiken onder zowel linux/unix als windows.
Zet het scriptje in een file.
Run de file via je terminal en vul een mac in.

Code:
  1. #!/usr/bin/perl -w
  2.  
  3. print "Enter Mac: ";
  4.  
  5. #retrieve input
  6. chomp(my $input = <STDIN>);
  7. my $newmac;
  8.  
  9. #determine wich format the mac is
  10. if ($input =~ /[A-f0-9]{2}:[A-f0-9]{2}:[A-f0-9]{2}:[A-f0-9]{2}:[A-f0-9]{2}:[A-f0-9]{2}/) {
  11.  
  12. #convert to cisco mac format
  13. my @splitmac = split(/:/, $input);
  14. $newmac = $splitmac[0].$splitmac[1].".".$splitmac[2].$splitmac[3].".".$splitmac[4].$splitmac[5];
  15. print $newmac;
  16.  
  17. } elsif ($input =~ /[A-f0-9]{4}\.[A-f0-9]{4}\.[A-f0-9]{4}/) {
  18.  
  19. #convert to standard mac format
  20. my @splitmac = split(/\./, $input);
  21. foreach (@splitmac) {
  22.  
  23. my @macpieces;
  24. my $start = 0;
  25.  
  26. push (@macpieces, substr($_, $start, 2));
  27. $start = $start + 2;
  28. push (@macpieces, substr($_, $start, 2));
  29.  
  30. foreach (@macpieces) {
  31.  
  32. $newmac = $newmac.":".$_;
  33. }
  34.  
  35. }
  36.  
  37. $newmac = substr($newmac, 1);
  38. print $newmac;
  39.  
  40. } else {
  41.  
  42. print "Format not recognized";
  43.  
  44. }
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Geen reacties (0)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.02s