Advertisement
j_melis

Untitled

Apr 19th, 2011
405
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.80 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. NETMASK=255.255.255.0
  4.  
  5. function mac2ip {
  6.     local MAC=$1
  7.     echo $(printf %d.%d.%d.%d 0x$(echo $MAC |cut -d ':' -f 3) 0x$(echo $MAC |cut -d ':' -f 4) 0x$(echo $MAC |cut -d ':' -f 5) 0x$(echo $MAC |cut -d ':' -f 6))
  8. }
  9. function mac2gw {
  10.     local MAC=$1
  11.     echo $(printf %d.%d.%d.1 0x$(echo $MAC |cut -d ':' -f 3) 0x$(echo $MAC |cut -d ':' -f 4) 0x$(echo $MAC |cut -d ':' -f 5))
  12. }
  13.  
  14. function get_interfaces() {
  15.     IFCMD="/sbin/ifconfig -a"
  16.     $IFCMD | grep ^eth | sed 's/ *Link encap:Ethernet.*HWaddr /-/g'
  17. }
  18.  
  19. for i in `get_interfaces`; do
  20.     IFACE=`echo $i|cut -d'-' -f1`
  21.     MAC=`echo $i|cut -d'-' -f2`
  22.     IP=`mac2ip $MAC`
  23.  
  24.     ifconfig $IFACE $IP netmask $NETMASK up
  25.  
  26.     if [ "$IFACE" = "eth0" ]; then
  27.         GW=`mac2gw $MAC`
  28.         route add default gw $GW
  29.     fi
  30. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement