Checking for a valid MAC Address


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking for a valid MAC Address
# 1  
Old 05-09-2011
Checking for a valid MAC Address

I have a ksh script and would like to validate a MAC address that is input by the user:
00:14:4F:FC:00:49
example:

Code:
MAC=`/usr/bin/ckint -p "Enter MAC address"`
echo $MAC
echo " "

Obviously chkint will not work, but does anyone have any suggestions?

Thanks
# 2  
Old 05-09-2011
Does this give you some ideas?

Code:
$ echo A2:12:DF | tr -d "[:digit:]" | tr -d [:ABCDEF]

$ echo A2:12:DF:2Z | tr -d "[:digit:]" | tr -d [:ABCDEF]
Z

So, any output would mean an invalid character.
# 3  
Old 05-09-2011
Ive never used chkint, but this should work after the mac is input

Code:
MAC=$(echo $MAC | sed "s/\(.*\)/\L\1/")
case $MAC
in 
  [0-9a-f][0-9a-f]:[0-9a-z][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f])
    echo "Valid MAC"
  ;;
  *) echo "Try again"
  ;;
esac

# 4  
Old 05-09-2011
Code:
#!/bin/ksh93

while :
do
   read MAC?"Enter MAC address: "
   case "$MAC" in
       ({2}([[:xdigit:]]){5}(:{2}([[:xdigit:]])))
       break;;
   esac
   echo "Invalid MAC address"
done

# 5  
Old 05-10-2011
Quote:
Originally Posted by fpmurphy
Code:
#!/bin/ksh93

while :
do
   read MAC?"Enter MAC address: "
   case "$MAC" in
       ({2}([[:xdigit:]]){5}(:{2}([[:xdigit:]])))
       break;;
   esac
   echo "Invalid MAC address"
done


`(' unexpected..........

What is the purpose of the : after while?

Thanks
# 6  
Old 05-10-2011
It is equivalent to "while true" in this shell script. You can use "while true" - the more common and documented syntax - instead of "while :" if you so wish.
# 7  
Old 05-10-2011
Quote:
Originally Posted by fpmurphy
Code:
#!/bin/ksh93

while :
do
   read MAC?"Enter MAC address: "
   case "$MAC" in
       ({2}([[:xdigit:]]){5}(:{2}([[:xdigit:]])))
       break;;
   esac
   echo "Invalid MAC address"
done

Not too much luck with that code, I have never used xdigit before.....
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. IP Networking

MAC Address - Four Interfaces with the same MAC Address

four interfaces with ifconfig all interfaces have the same mac. If is not set for unique. but it still works. what difference does it make to have all macs the same or different? (4 Replies)
Discussion started by: rrodgers
4 Replies

2. Shell Programming and Scripting

Valid date checking in the file

File contian below data... 20111101 20111102 20111131 I am new to unix and per scirpt... First two records are valid and last record is invalid,how to get the valid records... Please help me unix or perl script. :wall: Thanks, Murali (5 Replies)
Discussion started by: muralikri
5 Replies

3. Solaris

XDMCP fatal error: Session declined No valid address

Hello all, I just post here to expose an issue I have encountered two days ago and finally successfully solve just right now using info on this site( but not only). Config : Two SUN/ORACLE sparc Solaris 10 system. Purpose : do a remote CDE login from host one to the host two. method: from... (0 Replies)
Discussion started by: sunsunsun
0 Replies

4. IP Networking

Tracing a MAC address to IP address: Solaris

Hi there I lost connectivity to one of our remote systems and when I checked the messages log I found the following: Aug 10 23:42:34 host xntpd: time reset (step) 1.681729 s Aug 16 13:20:51 host ip: WARNING: node "mac address" is using our IP address x.x.x.x on aggr1 Aug 16 13:20:51 host... (9 Replies)
Discussion started by: notreallyhere
9 Replies

5. Solaris

Get ip address from mac address

I have following message in my messages file on solaris 10 WARNING: e1000g3712000:3 has duplicate address 010.022.196.011 (in use by 00:50:56:85:25:ef); disabled Now is there any way i can find which server has 00:50:56:85:25:ef mac address either IP or Hostname ? (6 Replies)
Discussion started by: fugitive
6 Replies

6. Solaris

XDMCP fatal error: Session declined No valid address

Hi ppl, anyone has encounter this error before? I can't remote login to another machine residing in the same subnet via CDE and the error I get in var/dt/Xerrors is XDMCP fatal error: Session declined No valid address Warning: Name: submenu_options_button Class: XmRowColumn ... (2 Replies)
Discussion started by: xiaochensg
2 Replies

7. Shell Programming and Scripting

checking valid values in variable

I'm using the following in my script. if echo $cpuidle |/usr/bin/egrep ; then when I issue this statement it issues the value of the variable back to stdout which ends up in my output file. Is there a better way to write this? I'm using ksh on solaris 9. (3 Replies)
Discussion started by: MizzGail
3 Replies

8. Shell Programming and Scripting

Checking the valid paths in the shell script

Hi i am using a shell script for renaming the files and placing in the remote location(FTP) my code is: cd $1 day=$(date +%d) for i in `ls -1 BBW*` do last=`tail -1 $i` pat=`expr "$last" : '.*(\(.*\)).*'` pat=`echo $pat | sed 's/ /_/'` pat=$pat$day mv $i $pat rm -f $day done... (3 Replies)
Discussion started by: srivsn
3 Replies

9. IP Networking

How to Achive IP address through MAC(Ethernet) address

Hi sir, i want to make such programe which takes MAC(Ethernet) address of any host & give me its IP address....... but i'm nt getting that how i can pass the MAC address to Frame........ Please give me an idea for making such program... Thanks & regards Krishna (3 Replies)
Discussion started by: krishnacins
3 Replies
Login or Register to Ask a Question