BASH   11

retrieveip.txt

Guest on 4th June 2021 09:06:19 AM

  1. #!/bin/bash
  2. #
  3. # retreiveip.txt - Script containing two functions to automatically grab IP dynamically
  4. #
  5. # Copyright (C) Oskar Andreasson <bluefluxATkoffeinDOTnet>
  6. #
  7. # Originally written and provided by Jelle Kalf <jkalfATunoDOTnl>. All
  8. # greetings, thanks and feedback should be sent to him for this script.
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation; version 2 of the License.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program or from the site that you downloaded it
  21. # from; if not, write to the Free Software Foundation, Inc., 59 Temple
  22. # Place, Suite 330, Boston, MA  02111-1307   USA
  23. #
  24.  
  25. RetrieveIP() {
  26.   nic="$1"
  27.   TEMP=""
  28.  
  29.   if ! /sbin/ifconfig | grep $nic > /dev/null; then
  30.     echo -e "\n\n interface $nic does not exist...  Aborting!"
  31.     exit 1;
  32.   fi
  33.  
  34.   TEMP=`ifconfig $nic | awk '/inet addr/ { gsub(".*:", "", $2) ; print
  35. $2 }'`
  36.  
  37.   if [ "$TEMP" = '' ]; then
  38.     echo "Aborting: Unable to determine the IP of $nic ... DHCP problem?"
  39.     exit 1
  40.   fi
  41. }
  42.  
  43. RetrieveBC() {
  44.   nic="$1"
  45.   BROADCAST=`ifconfig $nic | awk '/inet addr/ { gsub(".*:", "", $3) ; print $3 }'`
  46. }

Raw Paste


Login or Register to edit or fork this paste. It's free.